码迷,mamicode.com
首页 > 其他好文 > 详细

Aha code Three

时间:2016-02-16 22:01:38      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:

1. 坑爹的奥数

a. xxx+xxx=xxx(x为1~9,每个使用一次), method 1
#include <stdio.h>
int main(void)
{
    int a, b, c, d, e, f, g, h, i, total=0;
    for(a=1; a<=9; a++)
    for(b=1; b<=9; b++)
    for(c=1; c<=9; c++)
    for(d=1; d<=9; d++)
    for(e=1; e<=9; e++)
    for(f=1; f<=9; f++)
    for(g=1; g<=9; g++)
    for(h=1; h<=9; h++)
    for(i=1; i<=9; i++)
    {
        if(a!=b && a!=c && a!=d && a!=e && a!=f && a!=g && a!=h && a!=i 
                && b!=c && b!=d && b!=e && b!=f && b!=g && b!=h && b!=i
                        && c!=d && c!=e && c!=f && c!=g && c!=h && c!=i
                            && d!=e && d!=f && d!=g && d!=h && d!=i
                            && e!=f && e!=g && e!=h && e!=i
                                    && f!=g && f!=h && f!=i
                                       && g!=h && g!=i
                                    && h!=i
                && a*100+b*10+c+d*100+e*10+f == g*100+h*10+i)    
        {
            total++;
            printf("%d%d%d+%d%d%d = %d%d%d\n", a, b, c, d, e, f, g, h, i);    
        }
    }
    printf("total = %d", total/2);
    getchar();
    getchar();
    return 0;
}
/*编译执行
ray@ray-Lenovo:~/Documents/Exec_important/aha/three_chapter$ ./1_enum01
124+659 = 783
125+739 = 864
127+359 = 486
127+368 = 495
128+367 = 495
128+439 = 567
129+357 = 486
129+438 = 567
129+654 = 783
129+735 = 864
134+658 = 792
135+729 = 864
138+429 = 567
138+654 = 792
139+428 = 567
139+725 = 864
142+596 = 738
142+695 = 837
143+586 = 729
145+692 = 837
146+583 = 729
146+592 = 738
152+487 = 639
152+784 = 936
154+629 = 783
154+638 = 792
154+782 = 936
157+329 = 486
157+482 = 639
158+634 = 792
159+327 = 486
159+624 = 783
162+387 = 549
162+783 = 945
163+782 = 945
167+328 = 495
167+382 = 549
168+327 = 495
173+286 = 459
173+295 = 468
175+293 = 468
176+283 = 459
182+367 = 549
182+394 = 576
182+457 = 639
182+493 = 675
182+754 = 936
182+763 = 945
183+276 = 459
183+492 = 675
183+546 = 729
183+762 = 945
184+392 = 576
184+752 = 936
186+273 = 459
186+543 = 729
187+362 = 549
187+452 = 639
192+384 = 576
192+483 = 675
192+546 = 738
192+645 = 837
193+275 = 468
193+482 = 675
194+382 = 576
195+273 = 468
195+642 = 837
196+542 = 738
214+569 = 783
214+659 = 873
215+478 = 693
215+748 = 963
216+378 = 594
216+738 = 954
218+349 = 567
218+376 = 594
218+439 = 657
218+475 = 693
218+736 = 954
218+745 = 963
219+348 = 567
219+438 = 657
219+564 = 783
219+654 = 873
234+657 = 891
235+746 = 981
236+718 = 954
236+745 = 981
237+654 = 891
238+419 = 657
238+716 = 954
239+418 = 657
241+596 = 837
243+576 = 819
243+675 = 918
245+673 = 918
245+718 = 963
245+736 = 981
246+573 = 819
246+591 = 837
246+735 = 981
248+319 = 567
248+715 = 963
249+318 = 567
251+397 = 648
254+619 = 873
254+637 = 891
257+391 = 648
257+634 = 891
259+614 = 873
264+519 = 783
269+514 = 783
271+593 = 864
271+683 = 954
273+186 = 459
273+195 = 468
273+546 = 819
273+591 = 864
273+645 = 918
273+681 = 954
275+193 = 468
275+418 = 693
275+643 = 918
276+183 = 459
276+318 = 594
276+543 = 819
278+316 = 594
278+415 = 693
281+394 = 675
281+673 = 954
283+176 = 459
283+671 = 954
284+391 = 675
286+173 = 459
291+357 = 648
291+384 = 675
291+546 = 837
291+573 = 864
293+175 = 468
293+571 = 864
294+381 = 675
295+173 = 468
296+541 = 837
297+351 = 648
314+658 = 972
316+278 = 594
317+529 = 846
317+628 = 945
318+249 = 567
318+276 = 594
318+627 = 945
318+654 = 972
319+248 = 567
319+527 = 846
324+567 = 891
324+657 = 981
327+159 = 486
327+168 = 495
327+519 = 846
327+564 = 891
327+618 = 945
327+654 = 981
328+167 = 495
328+617 = 945
329+157 = 486
329+517 = 846
341+586 = 927
342+576 = 918
346+572 = 918
346+581 = 927
348+219 = 567
349+218 = 567
351+297 = 648
352+467 = 819
354+618 = 972
354+627 = 981
357+129 = 486
357+291 = 648
357+462 = 819
357+624 = 981
358+614 = 972
359+127 = 486
362+187 = 549
362+457 = 819
364+527 = 891
367+128 = 495
367+182 = 549
367+452 = 819
367+524 = 891
368+127 = 495
372+546 = 918
376+218 = 594
376+542 = 918
378+216 = 594
381+294 = 675
381+546 = 927
382+167 = 549
382+194 = 576
384+192 = 576
384+291 = 675
386+541 = 927
387+162 = 549
391+257 = 648
391+284 = 675
392+184 = 576
394+182 = 576
394+281 = 675
397+251 = 648
415+278 = 693
418+239 = 657
418+275 = 693
419+238 = 657
428+139 = 567
429+138 = 567
438+129 = 567
438+219 = 657
439+128 = 567
439+218 = 657
452+187 = 639
452+367 = 819
457+182 = 639
457+362 = 819
462+357 = 819
467+352 = 819
475+218 = 693
478+215 = 693
482+157 = 639
482+193 = 675
483+192 = 675
487+152 = 639
492+183 = 675
493+182 = 675
514+269 = 783
517+329 = 846
519+264 = 783
519+327 = 846
524+367 = 891
527+319 = 846
527+364 = 891
529+317 = 846
541+296 = 837
541+386 = 927
542+196 = 738
542+376 = 918
543+186 = 729
543+276 = 819
546+183 = 729
546+192 = 738
546+273 = 819
546+291 = 837
546+372 = 918
546+381 = 927
564+219 = 783
564+327 = 891
567+324 = 891
569+214 = 783
571+293 = 864
572+346 = 918
573+246 = 819
573+291 = 864
576+243 = 819
576+342 = 918
581+346 = 927
583+146 = 729
586+143 = 729
586+341 = 927
591+246 = 837
591+273 = 864
592+146 = 738
593+271 = 864
596+142 = 738
596+241 = 837
614+259 = 873
614+358 = 972
617+328 = 945
618+327 = 945
618+354 = 972
619+254 = 873
624+159 = 783
624+357 = 981
627+318 = 945
627+354 = 981
628+317 = 945
629+154 = 783
634+158 = 792
634+257 = 891
637+254 = 891
638+154 = 792
642+195 = 837
643+275 = 918
645+192 = 837
645+273 = 918
654+129 = 783
654+138 = 792
654+219 = 873
654+237 = 891
654+318 = 972
654+327 = 981
657+234 = 891
657+324 = 981
658+134 = 792
658+314 = 972
659+124 = 783
659+214 = 873
671+283 = 954
673+245 = 918
673+281 = 954
675+243 = 918
681+273 = 954
683+271 = 954
692+145 = 837
695+142 = 837
715+248 = 963
716+238 = 954
718+236 = 954
718+245 = 963
725+139 = 864
729+135 = 864
735+129 = 864
735+246 = 981
736+218 = 954
736+245 = 981
738+216 = 954
739+125 = 864
745+218 = 963
745+236 = 981
746+235 = 981
748+215 = 963
752+184 = 936
754+182 = 936
762+183 = 945
763+182 = 945
782+154 = 936
782+163 = 945
783+162 = 945
784+152 = 936
total = 168
*/

 

b. xxx+xxx=xxx(x为1~9,每个使用一次), method 2
#include <stdio.h> int main(void) { int a[10], i, total=0, book[10], sum; for(a[1]=1; a[1]<=9; a[1]++) for(a[2]=1; a[2]<=9; a[2]++) for(a[3]=1; a[3]<=9; a[3]++) for(a[4]=1; a[4]<=9; a[4]++) for(a[5]=1; a[5]<=9; a[5]++) for(a[6]=1; a[6]<=9; a[6]++) for(a[7]=1; a[7]<=9; a[7]++) for(a[8]=1; a[8]<=9; a[8]++) for(a[9]=1; a[9]<=9; a[9]++) { for(i=1; i<=9; i++)//初始化book数组 book[i] = 0; for(i=1; i<=9; i++)//如果某个数出现过就标记一下 book[a[i]] = 1; //统计共出现了多少个不同的数 sum = 0; for(i=1; i<=9; i++) sum+=book[i]; //如果正好出现了9个不同的数,并且满足等式条件,则输出 if(sum==9 && a[1]*100+a[2]*10+a[3]+a[4]*100+a[5]*10+a[6] == a[7]*100+a[8]*10+a[9]) { total++; printf("%d%d%d+%d%d%d = %d%d%d\n", a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]); } } printf("total=%d", total/2); getchar(); getchar(); return 0; } /*编译执行 ray@ray-Lenovo:~/Documents/Exec_important/aha/three_chapter$ ./1_enum02 124+659 = 783 125+739 = 864 127+359 = 486 127+368 = 495 128+367 = 495 128+439 = 567 129+357 = 486 129+438 = 567 129+654 = 783 129+735 = 864 134+658 = 792 135+729 = 864 138+429 = 567 138+654 = 792 139+428 = 567 139+725 = 864 142+596 = 738 142+695 = 837 143+586 = 729 145+692 = 837 146+583 = 729 146+592 = 738 152+487 = 639 152+784 = 936 154+629 = 783 154+638 = 792 154+782 = 936 157+329 = 486 157+482 = 639 158+634 = 792 159+327 = 486 159+624 = 783 162+387 = 549 162+783 = 945 163+782 = 945 167+328 = 495 167+382 = 549 168+327 = 495 173+286 = 459 173+295 = 468 175+293 = 468 176+283 = 459 182+367 = 549 182+394 = 576 182+457 = 639 182+493 = 675 182+754 = 936 182+763 = 945 183+276 = 459 183+492 = 675 183+546 = 729 183+762 = 945 184+392 = 576 184+752 = 936 186+273 = 459 186+543 = 729 187+362 = 549 187+452 = 639 192+384 = 576 192+483 = 675 192+546 = 738 192+645 = 837 193+275 = 468 193+482 = 675 194+382 = 576 195+273 = 468 195+642 = 837 196+542 = 738 214+569 = 783 214+659 = 873 215+478 = 693 215+748 = 963 216+378 = 594 216+738 = 954 218+349 = 567 218+376 = 594 218+439 = 657 218+475 = 693 218+736 = 954 218+745 = 963 219+348 = 567 219+438 = 657 219+564 = 783 219+654 = 873 234+657 = 891 235+746 = 981 236+718 = 954 236+745 = 981 237+654 = 891 238+419 = 657 238+716 = 954 239+418 = 657 241+596 = 837 243+576 = 819 243+675 = 918 245+673 = 918 245+718 = 963 245+736 = 981 246+573 = 819 246+591 = 837 246+735 = 981 248+319 = 567 248+715 = 963 249+318 = 567 251+397 = 648 254+619 = 873 254+637 = 891 257+391 = 648 257+634 = 891 259+614 = 873 264+519 = 783 269+514 = 783 271+593 = 864 271+683 = 954 273+186 = 459 273+195 = 468 273+546 = 819 273+591 = 864 273+645 = 918 273+681 = 954 275+193 = 468 275+418 = 693 275+643 = 918 276+183 = 459 276+318 = 594 276+543 = 819 278+316 = 594 278+415 = 693 281+394 = 675 281+673 = 954 283+176 = 459 283+671 = 954 284+391 = 675 286+173 = 459 291+357 = 648 291+384 = 675 291+546 = 837 291+573 = 864 293+175 = 468 293+571 = 864 294+381 = 675 295+173 = 468 296+541 = 837 297+351 = 648 314+658 = 972 316+278 = 594 317+529 = 846 317+628 = 945 318+249 = 567 318+276 = 594 318+627 = 945 318+654 = 972 319+248 = 567 319+527 = 846 324+567 = 891 324+657 = 981 327+159 = 486 327+168 = 495 327+519 = 846 327+564 = 891 327+618 = 945 327+654 = 981 328+167 = 495 328+617 = 945 329+157 = 486 329+517 = 846 341+586 = 927 342+576 = 918 346+572 = 918 346+581 = 927 348+219 = 567 349+218 = 567 351+297 = 648 352+467 = 819 354+618 = 972 354+627 = 981 357+129 = 486 357+291 = 648 357+462 = 819 357+624 = 981 358+614 = 972 359+127 = 486 362+187 = 549 362+457 = 819 364+527 = 891 367+128 = 495 367+182 = 549 367+452 = 819 367+524 = 891 368+127 = 495 372+546 = 918 376+218 = 594 376+542 = 918 378+216 = 594 381+294 = 675 381+546 = 927 382+167 = 549 382+194 = 576 384+192 = 576 384+291 = 675 386+541 = 927 387+162 = 549 391+257 = 648 391+284 = 675 392+184 = 576 394+182 = 576 394+281 = 675 397+251 = 648 415+278 = 693 418+239 = 657 418+275 = 693 419+238 = 657 428+139 = 567 429+138 = 567 438+129 = 567 438+219 = 657 439+128 = 567 439+218 = 657 452+187 = 639 452+367 = 819 457+182 = 639 457+362 = 819 462+357 = 819 467+352 = 819 475+218 = 693 478+215 = 693 482+157 = 639 482+193 = 675 483+192 = 675 487+152 = 639 492+183 = 675 493+182 = 675 514+269 = 783 517+329 = 846 519+264 = 783 519+327 = 846 524+367 = 891 527+319 = 846 527+364 = 891 529+317 = 846 541+296 = 837 541+386 = 927 542+196 = 738 542+376 = 918 543+186 = 729 543+276 = 819 546+183 = 729 546+192 = 738 546+273 = 819 546+291 = 837 546+372 = 918 546+381 = 927 564+219 = 783 564+327 = 891 567+324 = 891 569+214 = 783 571+293 = 864 572+346 = 918 573+246 = 819 573+291 = 864 576+243 = 819 576+342 = 918 581+346 = 927 583+146 = 729 586+143 = 729 586+341 = 927 591+246 = 837 591+273 = 864 592+146 = 738 593+271 = 864 596+142 = 738 596+241 = 837 614+259 = 873 614+358 = 972 617+328 = 945 618+327 = 945 618+354 = 972 619+254 = 873 624+159 = 783 624+357 = 981 627+318 = 945 627+354 = 981 628+317 = 945 629+154 = 783 634+158 = 792 634+257 = 891 637+254 = 891 638+154 = 792 642+195 = 837 643+275 = 918 645+192 = 837 645+273 = 918 654+129 = 783 654+138 = 792 654+219 = 873 654+237 = 891 654+318 = 972 654+327 = 981 657+234 = 891 657+324 = 981 658+134 = 792 658+314 = 972 659+124 = 783 659+214 = 873 671+283 = 954 673+245 = 918 673+281 = 954 675+243 = 918 681+273 = 954 683+271 = 954 692+145 = 837 695+142 = 837 715+248 = 963 716+238 = 954 718+236 = 954 718+245 = 963 725+139 = 864 729+135 = 864 735+129 = 864 735+246 = 981 736+218 = 954 736+245 = 981 738+216 = 954 739+125 = 864 745+218 = 963 745+236 = 981 746+235 = 981 748+215 = 963 752+184 = 936 754+182 = 936 762+183 = 945 763+182 = 945 782+154 = 936 782+163 = 945 783+162 = 945 784+152 = 936 total=168 */

 

Aha code Three

标签:

原文地址:http://www.cnblogs.com/try-again/p/5193792.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!