| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1602 人关注过本帖
标题:求助 数字 编程
只看楼主 加入收藏
zengzhw
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-4-10
结帖率:0
收藏
已结贴  问题点数:20 回复次数:7 
求助 数字 编程
用0到9的数字,随机抽取,数字不能重复,然后差不多是一个一位数加一个两位数加一个三位数的,得到一个四位数, 输出所有可能的答案,并输出总的可能性,还要有加号,和横线。用程序写出来。
搜索更多相关主题的帖子: 可能性 
2015-04-10 13:24
向洪林
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:重庆市奉节县
等 级:版主
威 望:9
帖 子:118
专家分:405
注 册:2015-3-10
收藏
得分:7 

新手上路,望大家多多照顾,谢谢!
2015-04-10 13:32
zengzhw
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-4-10
收藏
得分:0 
回复 2楼 向洪林
额,哥们那是几个意思?会么?急求。我刚入门。。
2015-04-10 13:34
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:7 
没看懂是啥意思   最好是举例说明

DO IT YOURSELF !
2015-04-10 13:35
lowrie
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:81
专家分:138
注 册:2015-3-12
收藏
得分:7 
是不是用0,1,2,3,4,5,6,7,8,9来组成4个数,一个一位数,一个两位数,一个三位数,一个四位数,要求数字不重复出现并且
    一位数  +  两位数  +  三位数  =  四位数
2015-04-10 14:00
lowrie
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:81
专家分:138
注 册:2015-3-12
收藏
得分:0 
如果我的理解对的的话,下边是我的代码,是java的,你把它变成c的就可以了

2 + 46 + 987 = 1035
2 + 47 + 986 = 1035
2 + 86 + 947 = 1035
2 + 87 + 946 = 1035
2 + 64 + 987 = 1053
2 + 67 + 984 = 1053
2 + 84 + 967 = 1053
2 + 87 + 964 = 1053
3 + 45 + 978 = 1026
3 + 48 + 975 = 1026
3 + 75 + 948 = 1026
3 + 78 + 945 = 1026
4 + 35 + 987 = 1026
4 + 37 + 985 = 1026
4 + 85 + 937 = 1026
4 + 87 + 935 = 1026
4 + 62 + 987 = 1053
4 + 67 + 982 = 1053
4 + 82 + 967 = 1053
4 + 87 + 962 = 1053
5 + 34 + 987 = 1026
5 + 37 + 984 = 1026
5 + 43 + 978 = 1026
5 + 48 + 973 = 1026
5 + 73 + 948 = 1026
5 + 78 + 943 = 1026
5 + 84 + 937 = 1026
5 + 87 + 934 = 1026
6 + 42 + 987 = 1035
6 + 47 + 982 = 1035
6 + 82 + 947 = 1035
6 + 87 + 942 = 1035
7 + 34 + 985 = 1026
7 + 35 + 984 = 1026
7 + 84 + 935 = 1026
7 + 85 + 934 = 1026
7 + 42 + 986 = 1035
7 + 46 + 982 = 1035
7 + 82 + 946 = 1035
7 + 86 + 942 = 1035
7 + 62 + 984 = 1053
7 + 64 + 982 = 1053
7 + 82 + 964 = 1053
7 + 84 + 962 = 1053
8 + 43 + 975 = 1026
8 + 45 + 973 = 1026
8 + 73 + 945 = 1026
8 + 75 + 943 = 1026
package com.example.aaa;

public class Shu {

    public static void main(String[] args) {

        shu();
   
    }
    public static void shu(){
        int[] a = new int[10];
        for (int i = 0; i < a.length; i++) {
            a[i] = 0;
        }
        for (int i = 0; i <= 9; i++) {
            for (int j = 1023; j <= 1056; j++) {
                for (int k = 10; k <= 98; k++) {
                    for (int l = 801; l <= 987; l++) {
                        if (i + k + l == j) {
                            int[] ba=shua(i, k, l, j);
                            boolean as = true;
                            for (int b = 0; b < 10; b++) {
                                if (ba[b] != 1) {
                                    as = false;
                                    break;
                                }

                            }
                            if(as==true){
                                System.out.println(i + " + "+ k + " + "+l+" = "+j );
                            }

                        }
                    }
                }
            }
        }
        
        
    }
    public static int[] shua(int one,int two,int three,int four){
        int[] a=new int[10];
        for (int i = 0; i < a.length; i++) {
            a[i]=0;
        }
        for (int i = 0; i < 4; i++) {
            a[four%10]=1;
            four=four/10;
        }
        for (int i = 0; i < 3; i++) {
            a[three%10]=1;
            three=three/10;
        }
        for (int i = 0; i < 2; i++) {
            a[two%10]=1;
            two=two/10;
        }
        a[one]=1;
        return a;
    }
}
2015-04-10 14:55
zengzhw
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-4-10
收藏
得分:0 
回复 6楼 lowrie
恩,好的,谢谢。非常感谢朋友你的帮助。。嘿嘿
2015-04-10 14:58
lowrie
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:81
专家分:138
注 册:2015-3-12
收藏
得分:0 
代码有错,应该存在比1056大的数,所以改为2000吧,这个绝对够范围 新代码如下,当时没注意

package com.example.aaa;

public class Shu {

    public static void main(String[] args) {

        shu();
   
    }
    public static void shu(){
        int[] a = new int[10];
        for (int i = 0; i < a.length; i++) {
            a[i] = 0;
        }
        for (int i = 0; i <= 9; i++) {
            for (int j = 1023; j <= 2000; j++) {
                for (int k = 10; k <= 98; k++) {
                    for (int l = 801; l <= 987; l++) {
                        if (i + k + l == j) {
                            int[] ba=shua(i, k, l, j);
                            boolean as = true;
                            for (int b = 0; b < 10; b++) {
                                if (ba[b] != 1) {
                                    as = false;
                                    break;
                                }

                            }
                            if(as==true){
                                System.out.println(i + " + "+ k + " + "+l+" = "+j );
                            }

                        }
                    }
                }
            }
        }
        
        
    }
    public static int[] shua(int one,int two,int three,int four){
        int[] a=new int[10];
        for (int i = 0; i < a.length; i++) {
            a[i]=0;
        }
        for (int i = 0; i < 4; i++) {
            a[four%10]=1;
            four=four/10;
        }
        for (int i = 0; i < 3; i++) {
            a[three%10]=1;
            three=three/10;
        }
        for (int i = 0; i < 2; i++) {
            a[two%10]=1;
            two=two/10;
        }
        a[one]=1;
        return a;
    }
}
2015-04-10 15:05
快速回复:求助 数字 编程
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016570 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved