// プログラミングのお題スレ Part6©2ch.net // http://p...content-available-to-author-only...h.net/test/read.cgi/tech/1418278634/79 // // 79 名前:デフォルトの名無しさん [sage]: 2014/12/15(月) 06:54:35.57 ID:j2Z0Uluh // お題:以下の数式のそれぞれの□に 0 ~ 9 のいずれか一つを入れて数式を成立させたい。 // ただし、一つの数字を二つ以上の□に入れるということはできないとする。 // 整数の左端に 0 がある場合はそれを略す。例えば「012」は「12」に等しいとする。 // □×□□+□□□=□□□□ // 数式を成立させるような整数の組の総数を求めよう。 #include<stdio.h> int kekka_kosuu = 0; // 並べ替え結果処理 void kekka_shori(int *d, int len) { // □×□□+□□□=□□□□ if (d[0] * (d[1] * 10 + d[2]) + (d[3] * 100 + d[4] * 10 + d[5]) == d[6] * 1000 + d[7] * 100 + d[8] * 10 + d[9]) { kekka_kosuu++; printf("[%d] %d * %d%d + %d%d%d == %d%d%d%d\n", kekka_kosuu, d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9]); } } // len個の配列の右n個を左にスライド void narabe(int *d, int len, int n) { int i, j; int tmp; if (n <= 1) { kekka_shori(d, len); return; } for (j = 0; j < n; j++) { narabe(d, len, n - 1); tmp = d[len - n]; for (i = 0; i < n - 1; i++) { d[len - n + i] = d[len - n + i + 1]; } d[len - n + i] = tmp; } } int main() { int d[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; narabe(d, 10, 10); return 0; }
Standard input is empty
[1] 1 * 35 + 689 == 0724 [2] 1 * 37 + 489 == 0526 [3] 1 * 39 + 487 == 0526 [4] 1 * 39 + 685 == 0724 [5] 1 * 57 + 289 == 0346 [6] 1 * 58 + 369 == 0427 [7] 1 * 59 + 287 == 0346 [8] 1 * 59 + 368 == 0427 [9] 1 * 59 + 683 == 0742 [10] 1 * 59 + 764 == 0823 [11] 1 * 53 + 689 == 0742 [12] 1 * 54 + 769 == 0823 [13] 1 * 68 + 359 == 0427 [14] 1 * 69 + 358 == 0427 [15] 1 * 69 + 754 == 0823 [16] 1 * 64 + 759 == 0823 [17] 1 * 79 + 285 == 0364 [18] 1 * 79 + 483 == 0562 [19] 1 * 73 + 489 == 0562 [20] 1 * 75 + 289 == 0364 [21] 1 * 89 + 257 == 0346 [22] 1 * 89 + 275 == 0364 [23] 1 * 89 + 473 == 0562 [24] 1 * 89 + 437 == 0526 [25] 1 * 89 + 635 == 0724 [26] 1 * 89 + 653 == 0742 [27] 1 * 83 + 479 == 0562 [28] 1 * 83 + 659 == 0742 [29] 1 * 85 + 639 == 0724 [30] 1 * 85 + 279 == 0364 [31] 1 * 87 + 259 == 0346 [32] 1 * 87 + 439 == 0526 [33] 2 * 36 + 845 == 0917 [34] 2 * 38 + 491 == 0567 [35] 2 * 31 + 587 == 0649 [36] 2 * 31 + 794 == 0856 [37] 2 * 46 + 983 == 1075 [38] 2 * 43 + 695 == 0781 [39] 2 * 43 + 875 == 0961 [40] 2 * 58 + 947 == 1063 [41] 2 * 58 + 497 == 0613 [42] 2 * 59 + 716 == 0834 [43] 2 * 59 + 743 == 0861 [44] 2 * 53 + 968 == 1074 [45] 2 * 54 + 683 == 0791 [46] 2 * 54 + 863 == 0971 [47] 2 * 63 + 719 == 0845 [48] 2 * 63 + 845 == 0971 [49] 2 * 64 + 785 == 0913 [50] 2 * 64 + 731 == 0859 [51] 2 * 64 + 389 == 0517 [52] 2 * 78 + 413 == 0569 [53] 2 * 71 + 356 == 0498 [54] 2 * 73 + 695 == 0841 [55] 2 * 74 + 815 == 0963 [56] 2 * 76 + 893 == 1045 [57] 2 * 76 + 389 == 0541 [58] 2 * 89 + 167 == 0345 [59] 2 * 89 + 176 == 0354 [60] 2 * 89 + 473 == 0651 [61] 2 * 89 + 437 == 0615 [62] 2 * 89 + 563 == 0741 [63] 2 * 89 + 536 == 0714 [64] 2 * 83 + 491 == 0657 [65] 2 * 84 + 593 == 0761 [66] 2 * 84 + 197 == 0365 [67] 2 * 86 + 743 == 0915 [68] 2 * 86 + 347 == 0519 [69] 2 * 93 + 485 == 0671 [70] 2 * 94 + 875 == 1063 [71] 2 * 96 + 845 == 1037 [72] 2 * 97 + 164 == 0358 [73] 2 * 97 + 641 == 0835 [74] 3 * 45 + 786 == 0921 [75] 3 * 46 + 721 == 0859 [76] 3 * 49 + 715 == 0862 [77] 3 * 41 + 659 == 0782 [78] 3 * 42 + 765 == 0891 [79] 3 * 58 + 742 == 0916 [80] 3 * 52 + 691 == 0847 [81] 3 * 54 + 867 == 1029 [82] 3 * 61 + 295 == 0478 [83] 3 * 61 + 745 == 0928 [84] 3 * 78 + 261 == 0495 [85] 3 * 79 + 421 == 0658 [86] 3 * 71 + 482 == 0695 [87] 3 * 72 + 849 == 1065 [88] 3 * 74 + 629 == 0851 [89] 3 * 74 + 296 == 0518 [90] 3 * 82 + 451 == 0697 [91] 3 * 82 + 469 == 0715 [92] 3 * 84 + 267 == 0519 [93] 3 * 85 + 769 == 1024 [94] 3 * 86 + 794 == 1052 [95] 3 * 86 + 947 == 1205 [96] 3 * 87 + 945 == 1206 [97] 3 * 92 + 485 == 0761 [98] 3 * 95 + 182 == 0467 [99] 3 * 98 + 752 == 1046 [100] 3 * 14 + 587 == 0629 [101] 3 * 15 + 684 == 0729 [102] 3 * 19 + 685 == 0742 [103] 3 * 25 + 871 == 0946 [104] 3 * 27 + 984 == 1065 [105] 3 * 29 + 584 == 0671 [106] 3 * 29 + 764 == 0851 [107] 4 * 56 + 983 == 1207 [108] 4 * 59 + 827 == 1063 [109] 4 * 59 + 836 == 1072 [110] 4 * 53 + 617 == 0829 [111] 4 * 53 + 716 == 0928 [112] 4 * 67 + 825 == 1093 [113] 4 * 67 + 321 == 0589 [114] 4 * 68 + 935 == 1207 [115] 4 * 68 + 125 == 0397 [116] 4 * 68 + 521 == 0793 [117] 4 * 61 + 579 == 0823 [118] 4 * 63 + 529 == 0781 [119] 4 * 78 + 613 == 0925 [120] 4 * 79 + 516 == 0832 [121] 4 * 76 + 519 == 0823 [122] 4 * 89 + 167 == 0523 [123] 4 * 89 + 176 == 0532 [124] 4 * 89 + 257 == 0613 [125] 4 * 89 + 275 == 0631 [126] 4 * 89 + 356 == 0712 [127] 4 * 89 + 365 == 0721 [128] 4 * 82 + 351 == 0679 [129] 4 * 82 + 765 == 1093 [130] 4 * 83 + 695 == 1027 [131] 4 * 86 + 179 == 0523 [132] 4 * 92 + 317 == 0685 [133] 4 * 97 + 138 == 0526 [134] 4 * 98 + 635 == 1027 [135] 4 * 12 + 589 == 0637 [136] 4 * 16 + 759 == 0823 [137] 4 * 18 + 295 == 0367 [138] 4 * 19 + 756 == 0832 [139] 4 * 27 + 853 == 0961 [140] 4 * 27 + 583 == 0691 [141] 4 * 28 + 963 == 1075 [142] 4 * 28 + 639 == 0751 [143] 4 * 21 + 589 == 0673 [144] 4 * 21 + 769 == 0853 [145] 4 * 36 + 781 == 0925 [146] 4 * 38 + 569 == 0721 [147] 4 * 39 + 562 == 0718 [148] 4 * 39 + 625 == 0781 [149] 4 * 31 + 852 == 0976 [150] 5 * 67 + 908 == 1243 [151] 5 * 69 + 128 == 0473 [152] 5 * 69 + 137 == 0482 [153] 5 * 63 + 497 == 0812 [154] 5 * 63 + 182 == 0497 [155] 5 * 79 + 431 == 0826 [156] 5 * 71 + 284 == 0639 [157] 5 * 71 + 293 == 0648 [158] 5 * 71 + 329 == 0684 [159] 5 * 93 + 182 == 0647 [160] 5 * 93 + 281 == 0746 [161] 5 * 97 + 143 == 0628 [162] 5 * 97 + 341 == 0826 [163] 5 * 13 + 764 == 0829 [164] 5 * 17 + 284 == 0369 [165] 5 * 29 + 473 == 0618 [166] 5 * 37 + 296 == 0481 [167] 5 * 37 + 629 == 0814 [168] 5 * 39 + 281 == 0476 [169] 5 * 31 + 674 == 0829 [170] 5 * 31 + 692 == 0847 [171] 5 * 31 + 629 == 0784 [172] 5 * 47 + 968 == 1203 [173] 6 * 78 + 453 == 0921 [174] 6 * 79 + 850 == 1324 [175] 6 * 72 + 483 == 0915 [176] 6 * 73 + 421 == 0859 [177] 6 * 74 + 809 == 1253 [178] 6 * 74 + 908 == 1352 [179] 6 * 81 + 249 == 0735 [180] 6 * 82 + 547 == 1039 [181] 6 * 83 + 251 == 0749 [182] 6 * 87 + 903 == 1425 [183] 6 * 87 + 930 == 1452 [184] 6 * 92 + 485 == 1037 [185] 6 * 94 + 523 == 1087 [186] 6 * 94 + 253 == 0817 [187] 6 * 94 + 271 == 0835 [188] 6 * 97 + 823 == 1405 [189] 6 * 97 + 850 == 1432 [190] 6 * 98 + 437 == 1025 [191] 6 * 98 + 752 == 1340 [192] 6 * 12 + 387 == 0459 [193] 6 * 12 + 873 == 0945 [194] 6 * 13 + 847 == 0925 [195] 6 * 13 + 874 == 0952 [196] 6 * 18 + 249 == 0357 [197] 6 * 18 + 429 == 0537 [198] 6 * 19 + 358 == 0472 [199] 6 * 23 + 947 == 1085 [200] 6 * 24 + 813 == 0957 [201] 6 * 24 + 831 == 0975 [202] 6 * 28 + 349 == 0517 [203] 6 * 28 + 745 == 0913 [204] 6 * 29 + 413 == 0587 [205] 6 * 37 + 259 == 0481 [206] 6 * 37 + 592 == 0814 [207] 6 * 38 + 197 == 0425 [208] 6 * 38 + 251 == 0479 [209] 6 * 38 + 521 == 0749 [210] 6 * 31 + 289 == 0475 [211] 6 * 32 + 857 == 1049 [212] 6 * 47 + 539 == 0821 [213] 6 * 49 + 523 == 0817 [214] 6 * 42 + 579 == 0831 [215] 6 * 43 + 571 == 0829 [216] 6 * 52 + 481 == 0793 [217] 6 * 54 + 879 == 1203 [218] 6 * 54 + 978 == 1302 [219] 7 * 82 + 465 == 1039 [220] 7 * 82 + 960 == 1534 [221] 7 * 83 + 659 == 1240 [222] 7 * 93 + 214 == 0865 [223] 7 * 94 + 165 == 0823 [224] 7 * 96 + 832 == 1504 [225] 7 * 96 + 382 == 1054 [226] 7 * 98 + 356 == 1042 [227] 7 * 12 + 385 == 0469 [228] 7 * 18 + 523 == 0649 [229] 7 * 23 + 458 == 0619 [230] 7 * 24 + 895 == 1063 [231] 7 * 25 + 639 == 0814 [232] 7 * 25 + 864 == 1039 [233] 7 * 25 + 189 == 0364 [234] 7 * 21 + 439 == 0586 [235] 7 * 34 + 621 == 0859 [236] 7 * 35 + 824 == 1069 [237] 7 * 36 + 289 == 0541 [238] 7 * 38 + 425 == 0691 [239] 7 * 39 + 268 == 0541 [240] 7 * 39 + 412 == 0685 [241] 7 * 31 + 642 == 0859 [242] 7 * 32 + 845 == 1069 [243] 7 * 45 + 613 == 0928 [244] 7 * 45 + 298 == 0613 [245] 7 * 48 + 196 == 0532 [246] 7 * 48 + 295 == 0631 [247] 7 * 49 + 183 == 0526 [248] 7 * 41 + 296 == 0583 [249] 7 * 41 + 395 == 0682 [250] 7 * 41 + 539 == 0826 [251] 7 * 41 + 638 == 0925 [252] 7 * 42 + 391 == 0685 [253] 7 * 59 + 413 == 0826 [254] 7 * 53 + 491 == 0862 [255] 7 * 53 + 869 == 1240 [256] 7 * 53 + 248 == 0619 [257] 7 * 54 + 928 == 1306 [258] 7 * 54 + 982 == 1360 [259] 7 * 61 + 432 == 0859 [260] 7 * 62 + 419 == 0853 [261] 7 * 62 + 950 == 1384 [262] 7 * 62 + 149 == 0583 [263] 7 * 63 + 451 == 0892 [264] 7 * 63 + 541 == 0982 [265] 8 * 96 + 734 == 1502 [266] 8 * 96 + 275 == 1043 [267] 8 * 96 + 437 == 1205 [268] 8 * 96 + 572 == 1340 [269] 8 * 12 + 473 == 0569 [270] 8 * 12 + 653 == 0749 [271] 8 * 14 + 527 == 0639 [272] 8 * 14 + 257 == 0369 [273] 8 * 16 + 329 == 0457 [274] 8 * 17 + 356 == 0492 [275] 8 * 17 + 329 == 0465 [276] 8 * 19 + 374 == 0526 [277] 8 * 19 + 473 == 0625 [278] 8 * 23 + 491 == 0675 [279] 8 * 23 + 761 == 0945 [280] 8 * 24 + 761 == 0953 [281] 8 * 24 + 167 == 0359 [282] 8 * 26 + 743 == 0951 [283] 8 * 26 + 149 == 0357 [284] 8 * 27 + 149 == 0365 [285] 8 * 27 + 419 == 0635 [286] 8 * 37 + 950 == 1246 [287] 8 * 39 + 752 == 1064 [288] 8 * 32 + 419 == 0675 [289] 8 * 46 + 725 == 1093 [290] 8 * 46 + 905 == 1273 [291] 8 * 47 + 950 == 1326 [292] 8 * 47 + 239 == 0615 [293] 8 * 47 + 536 == 0912 [294] 8 * 47 + 653 == 1029 [295] 8 * 49 + 635 == 1027 [296] 8 * 41 + 239 == 0567 [297] 8 * 41 + 329 == 0657 [298] 8 * 42 + 617 == 0953 [299] 8 * 42 + 635 == 0971 [300] 8 * 43 + 572 == 0916 [301] 8 * 43 + 725 == 1069 [302] 8 * 43 + 752 == 1096 [303] 8 * 43 + 275 == 0619 [304] 8 * 56 + 293 == 0741 [305] 8 * 56 + 473 == 0921 [306] 8 * 59 + 734 == 1206 [307] 8 * 51 + 239 == 0647 [308] 8 * 54 + 239 == 0671 [309] 8 * 54 + 329 == 0761 [310] 8 * 69 + 473 == 1025 [311] 8 * 69 + 752 == 1304 [312] 8 * 61 + 437 == 0925 [313] 8 * 64 + 527 == 1039 [314] 8 * 64 + 239 == 0751 [315] 8 * 71 + 356 == 0924 [316] 8 * 72 + 365 == 0941 [317] 8 * 76 + 932 == 1540 [318] 9 * 13 + 628 == 0745 [319] 9 * 13 + 745 == 0862 [320] 9 * 14 + 632 == 0758 [321] 9 * 17 + 482 == 0635 [322] 9 * 23 + 857 == 1064 [323] 9 * 26 + 347 == 0581 [324] 9 * 28 + 463 == 0715 [325] 9 * 35 + 167 == 0482 [326] 9 * 38 + 125 == 0467 [327] 9 * 31 + 268 == 0547 [328] 9 * 31 + 547 == 0826 [329] 9 * 32 + 758 == 1046 [330] 9 * 47 + 215 == 0638 [331] 9 * 43 + 685 == 1072 [332] 9 * 43 + 271 == 0658 [333] 9 * 58 + 241 == 0763 [334] 9 * 58 + 214 == 0736 [335] 9 * 52 + 316 == 0784 [336] 9 * 53 + 284 == 0761 [337] 9 * 68 + 425 == 1037 [338] 9 * 68 + 740 == 1352 [339] 9 * 61 + 235 == 0784 [340] 9 * 61 + 325 == 0874 [341] 9 * 62 + 185 == 0743 [342] 9 * 65 + 143 == 0728 [343] 9 * 73 + 805 == 1462 [344] 9 * 74 + 836 == 1502 [345] 9 * 74 + 386 == 1052 [346] 9 * 76 + 358 == 1042 [347] 9 * 82 + 607 == 1345 [348] 9 * 84 + 570 == 1326 [349] 9 * 84 + 507 == 1263 [350] 9 * 85 + 637 == 1402