⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cryptarithm.c~

📁 People have vast background knowledge to cope with everyday situations. We don t have to be told e
💻 C~
字号:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** Description: cross + roads = danger with the extra condition that the digits    ** assigned to the letters at the beginning of all words (c, rand d) are not equal ** to 0, and of course such that the resulting algebraic expression is correct.    ** The output of your program, saved as cryptarithm.c, should be lines of the form **                                                                                 ** cross = ....., roads = ..... and danger = ...... is a solution.                 **                                                                                 **                                                                                 ** Written by Suiliang Qiu(student id=z3267009) for COMP9021                       ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include <stdio.h>#include <stdlib.h>#include <stdbool.h>#include <math.h>int main(void){    for (int first_text = 12033; first_text <= 98766; ++first_text)                {            int cross = first_text;            int roads=1;            int danger=1;            int c = cross / 10000;            int my_bits1 = 1 << c;            int r = (cross / 1000) % 10;                        if (r == 0)                continue;            if (( my_bits1 >> r) % 2)                continue;            my_bits1 +=  1 << r;            int o= (cross%1000)/100;            if (( my_bits1 >> o) % 2)                continue;            my_bits1 +=  1 << o;            int s= cross%10;            if (( my_bits1 >> s) % 2)                continue;            my_bits1 +=  1 << s;            int s2=cross/10%10;            if(s2!=s)                continue;            for (int second_text= 1; second_text <= 98; ++second_text)                {                    int my_bits2=my_bits1;                    int ad = second_text;;                    int a= ad/10;                    if (( my_bits2 >> a) % 2)                        continue;                    my_bits2 +=  1 << a;                    int d= ad%10;                    if(d==0)                        continue;                    if (( my_bits2 >> d) % 2)                        continue;                    my_bits2 +=  1 << d;                    roads=s+(ad*10)+o*1000+r*10000;                    for(int third_text=12;third_text<=987;++third_text)                        {                            int my_bits3=my_bits2;                            int nge=third_text;                            int n= nge/100;                            if (( my_bits3 >> n) % 2)                                continue;                            my_bits3 +=  1 << n;                            int g= (nge/10)%10;                            if (( my_bits3 >> g) % 2)                                continue;                            my_bits3 +=  1 << g;                            int e= nge%10;                            if (( my_bits3 >> e) % 2)                                continue;                            my_bits3 +=  1 << e;                            danger=r+nge*10+a*10000+d*100000;                            int result;                            result =roads+cross;                            if (danger==result)                                printf("cross=%d, roads=%d and  danger=%d is a solution\n",cross,roads,danger);                        }                                    }        }       return EXIT_SUCCESS;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -