马虎的算式

  • 本人解法 比较笨
public class Main {
    // 测试代码
    public static void main(String[] args) {
        // 定义一个字符串用于连接五个数字
        int sum = 0;
        for (int i = 10; i <= 99; i++) {
            for (int x = 100; x <= 999; x++) {
                String str = "";
                Boolean flag = true;
                str = str + i;
                str = str + x;
                // 用于记录每个字母出现的次数
                int[] arr = new int[10];
                for (int y = 0; y < 5; y++) {
                    String s = String.valueOf(str.charAt(y));
                    int value = Integer.parseInt(s);
                    arr[value]++;
                    if (arr[value] == 2 ||value ==0) {
                        flag = false;
                        break;
                    }
                }
                if (flag == true) {
                    String s1 = "";
                    String s2 = "";
                    s1 = s1 + String.valueOf(str.charAt(0));
                    s1 = s1 + String.valueOf(str.charAt(3));
                    s1 = s1 + String.valueOf(str.charAt(1));
                    s2 = s2 + String.valueOf(str.charAt(2));
                    s2 = s2 + String.valueOf(str.charAt(4));
                    int s3 = Integer.parseInt(s1);
                    int s4 = Integer.parseInt(s2);
                    if ((s3 * s4) == (i * x)) {
                        sum++;
                    }
                }
            }
        }
        System.out.println(sum);
    }
}

*另一种解法

public static void main(String[] args) {
        int sum = 0;
        for (int a = 1; a <= 9; a++) {
            for (int b = 1; b <= 9; b++) {
                if (b != a) {
                    for (int c = 1; c <= 9; c++) {
                        if (c != b && c != a) {
                            for (int d = 1; d <= 9; d++) {
                                if (d != c && d != b && d != a) {
                                    for (int e = 1; e <= 9; e++) {
                                        if (e != d && e != c && e != b && e != a) {
                                            if ((a * 10 + b) * (c * 100 + d * 10 + e) == (a * 100 + d * 10 + b)* (c * 10 + e)) {
                                                sum++;
                                                System.out.println(sum);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
全部评论

相关推荐

大猪蹄子哥:1-谁教你这么写教育经历的……咱都这个学历了,很多公司要看本科、硕士,Gap Year的,你啪就给一个上大26届硕士,没了。 2-那堆奖学金揉成一行放最后得了,放前面显得你没技术自信,还是那句话,对于咱这个学历直接上重点,你这上半段看起来像个大专(无恶意 3-专业技能最好点出来细化方向,你熟悉的以太网是UDP还是TCP,是千兆还是万兆等等,多种信号处理……那你倒是说两个啊,后面空着干嘛,会的干嘛不讲 4-项目经历废话太多,描述不专业(怎么还有我,我们这种词),没有数据支撑(是婴儿还是巨人看不出来)。最后如果这些是真的XX项目、比赛,最好点出来,不然更显得像自学着玩的,或者说抄的(经典复现等于我做过 5-个人总结在咱这个分段没用
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务