比如如下5位数:
26542
其中首先满足2+6+2=10,余下的5+4=9为比较大的数.
或者有如
56943
其中5+6+9=20
而4+3等于7
请大家给个思路,求5位数中3位相加等于10或20,余下两位相加最大的情况.

解决方案 »

  1.   

    不怎么明白你的意思。
    public class test {
    public static void main(String[] args) {
    for(int a = 9;a> -1;a--) {
    for(int b = 9;b > -1;b--) {
    for(int c = 9;c>-1;c--) {
    if((a + b + c) == 10) {
    System.out.println(10000*a + b*1000 + c* 100 + 99);
    }
    }
    }
    }
    }
    }
      

  2.   

    弄了个比较烂的写法:        int a,b,c,d,e;
            for(int i =10000;i<99999;i++)
            {
                a = i/10000;
                b = i%10000/1000;
                c = i%1000/100;
                d = i%100/10;
                e = i%10;
                if((a+b+c+d+e)==19 || (a+b+c+d+e)==29)
                {
                    System.out.println("这个5位数是:"+a+b+c+d+e);
                }
                else
                    continue;
      

  3.   


    public class TestNumber {
    public static void main(String[] args) {
    int i = 0;
    int count = 0;
    for(i=10000; i<100000; i++) {
    String str = String.valueOf(i);
    int num1 = Integer.parseInt("" + str.charAt(0)) + 
    Integer.parseInt("" + str.charAt(1)) +
    Integer.parseInt("" + str.charAt(2));
    int num2 = Integer.parseInt("" + str.charAt(3)) +
    Integer.parseInt("" + str.charAt(4));
    if(((num1==10) || (num1==20)) && (num2==9)) {
    count++;
    if(count%10==0)
    System.out.println();
    System.out.print(i + " ");
    }else
    continue;
    } }
    }
    楼主的意思看不明白
    是这样的吗? 前三位数之和为10或20,后两位数值和为9
      

  4.   

    现在看懂LZ的意思了,应该是这样的:
    假设五位数分别为:x1x2x3x4x5
    且五位数中,假设满足这样的条件:
    情况一:x1+x2+x3=10或者20,余下的两位相加即为x4+x5
    情况二:x1+x3+x5也等于10或者20,余下的两位相加即为x2+x4
    如果有x4+x5 > x2+x4
    那么“情况一”就是我们所要找的!因为它除了满足三个数之和为10或者20外,且满足余下的两位数之和为“相对”最大值!