読者です 読者をやめる 読者になる 読者になる

ソフトを作れといわれた。

ソースコード

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define OK 0
#define NG -1

int isOK(int i, int j ) {
	int a[10];
	int iSum,iTemp;
	int iCounter;
	int iMod;

	iSum = i+ j;
	if ( iSum > 999 ) {
		return NG;
	}
	for ( iCounter = 0; iCounter < 10; iCounter++ ) {
		a[iCounter] = 0;
	}
	iTemp = i + 1000*j + 1000000*iSum;
	while ( iTemp > 0 ) {
		iMod = iTemp % 10;
		iTemp /= 10;
		a[iMod]++;
	}

	for ( iCounter = 1; iCounter < 10; iCounter++ ) {
		if( a[iCounter] != 1) {
			return NG;
		}
	}
	return OK;
}

int main(int argc, char** argv ) {
	int i,j;
	int iNum = 1;
	for ( i = 102; i <= 987; i++ ) {
		for ( j = 102; j <= 987; j++ ) {
			if ( isOK( i, j ) == OK ) {
				fprintf( stdout, "[%3d] %d + %d = %d \n", iNum, i, j, i+j );
				iNum++;
			}
		}
	}
	return 0;
}

結果

[  1] 124 + 659 = 783 
[  2] 125 + 739 = 864 
[  3] 127 + 359 = 486 
[  4] 127 + 368 = 495 
[  5] 128 + 367 = 495 
[  6] 128 + 439 = 567 
[  7] 129 + 357 = 486 
[  8] 129 + 438 = 567 
[  9] 129 + 654 = 783 
[ 10] 129 + 735 = 864 
[ 11] 134 + 658 = 792 
[ 12] 135 + 729 = 864 
[ 13] 138 + 429 = 567 
[ 14] 138 + 654 = 792 
[ 15] 139 + 428 = 567 
[ 16] 139 + 725 = 864 
[ 17] 142 + 596 = 738 
[ 18] 142 + 695 = 837 
[ 19] 143 + 586 = 729 
[ 20] 145 + 692 = 837 
[ 21] 146 + 583 = 729 
[ 22] 146 + 592 = 738 
[ 23] 152 + 487 = 639 
[ 24] 152 + 784 = 936 
[ 25] 154 + 629 = 783 
[ 26] 154 + 638 = 792 
[ 27] 154 + 782 = 936 
[ 28] 157 + 329 = 486 
[ 29] 157 + 482 = 639 
[ 30] 158 + 634 = 792 
[ 31] 159 + 327 = 486 
[ 32] 159 + 624 = 783 
[ 33] 162 + 387 = 549 
[ 34] 162 + 783 = 945 
[ 35] 163 + 782 = 945 
[ 36] 167 + 328 = 495 
[ 37] 167 + 382 = 549 
[ 38] 168 + 327 = 495 
[ 39] 173 + 286 = 459 
[ 40] 173 + 295 = 468 
[ 41] 175 + 293 = 468 
[ 42] 176 + 283 = 459 
[ 43] 182 + 367 = 549 
[ 44] 182 + 394 = 576 
[ 45] 182 + 457 = 639 
[ 46] 182 + 493 = 675 
[ 47] 182 + 754 = 936 
[ 48] 182 + 763 = 945 
[ 49] 183 + 276 = 459 
[ 50] 183 + 492 = 675 
[ 51] 183 + 546 = 729 
[ 52] 183 + 762 = 945 
[ 53] 184 + 392 = 576 
[ 54] 184 + 752 = 936 
[ 55] 186 + 273 = 459 
[ 56] 186 + 543 = 729 
[ 57] 187 + 362 = 549 
[ 58] 187 + 452 = 639 
[ 59] 192 + 384 = 576 
[ 60] 192 + 483 = 675 
[ 61] 192 + 546 = 738 
[ 62] 192 + 645 = 837 
[ 63] 193 + 275 = 468 
[ 64] 193 + 482 = 675 
[ 65] 194 + 382 = 576 
[ 66] 195 + 273 = 468 
[ 67] 195 + 642 = 837 
[ 68] 196 + 542 = 738 
[ 69] 214 + 569 = 783 
[ 70] 214 + 659 = 873 
[ 71] 215 + 478 = 693 
[ 72] 215 + 748 = 963 
[ 73] 216 + 378 = 594 
[ 74] 216 + 738 = 954 
[ 75] 218 + 349 = 567 
[ 76] 218 + 376 = 594 
[ 77] 218 + 439 = 657 
[ 78] 218 + 475 = 693 
[ 79] 218 + 736 = 954 
[ 80] 218 + 745 = 963 
[ 81] 219 + 348 = 567 
[ 82] 219 + 438 = 657 
[ 83] 219 + 564 = 783 
[ 84] 219 + 654 = 873 
[ 85] 234 + 657 = 891 
[ 86] 235 + 746 = 981 
[ 87] 236 + 718 = 954 
[ 88] 236 + 745 = 981 
[ 89] 237 + 654 = 891 
[ 90] 238 + 419 = 657 
[ 91] 238 + 716 = 954 
[ 92] 239 + 418 = 657 
[ 93] 241 + 596 = 837 
[ 94] 243 + 576 = 819 
[ 95] 243 + 675 = 918 
[ 96] 245 + 673 = 918 
[ 97] 245 + 718 = 963 
[ 98] 245 + 736 = 981 
[ 99] 246 + 573 = 819 
[100] 246 + 591 = 837 
[101] 246 + 735 = 981 
[102] 248 + 319 = 567 
[103] 248 + 715 = 963 
[104] 249 + 318 = 567 
[105] 251 + 397 = 648 
[106] 254 + 619 = 873 
[107] 254 + 637 = 891 
[108] 257 + 391 = 648 
[109] 257 + 634 = 891 
[110] 259 + 614 = 873 
[111] 264 + 519 = 783 
[112] 269 + 514 = 783 
[113] 271 + 593 = 864 
[114] 271 + 683 = 954 
[115] 273 + 186 = 459 
[116] 273 + 195 = 468 
[117] 273 + 546 = 819 
[118] 273 + 591 = 864 
[119] 273 + 645 = 918 
[120] 273 + 681 = 954 
[121] 275 + 193 = 468 
[122] 275 + 418 = 693 
[123] 275 + 643 = 918 
[124] 276 + 183 = 459 
[125] 276 + 318 = 594 
[126] 276 + 543 = 819 
[127] 278 + 316 = 594 
[128] 278 + 415 = 693 
[129] 281 + 394 = 675 
[130] 281 + 673 = 954 
[131] 283 + 176 = 459 
[132] 283 + 671 = 954 
[133] 284 + 391 = 675 
[134] 286 + 173 = 459 
[135] 291 + 357 = 648 
[136] 291 + 384 = 675 
[137] 291 + 546 = 837 
[138] 291 + 573 = 864 
[139] 293 + 175 = 468 
[140] 293 + 571 = 864 
[141] 294 + 381 = 675 
[142] 295 + 173 = 468 
[143] 296 + 541 = 837 
[144] 297 + 351 = 648 
[145] 314 + 658 = 972 
[146] 316 + 278 = 594 
[147] 317 + 529 = 846 
[148] 317 + 628 = 945 
[149] 318 + 249 = 567 
[150] 318 + 276 = 594 
[151] 318 + 627 = 945 
[152] 318 + 654 = 972 
[153] 319 + 248 = 567 
[154] 319 + 527 = 846 
[155] 324 + 567 = 891 
[156] 324 + 657 = 981 
[157] 327 + 159 = 486 
[158] 327 + 168 = 495 
[159] 327 + 519 = 846 
[160] 327 + 564 = 891 
[161] 327 + 618 = 945 
[162] 327 + 654 = 981 
[163] 328 + 167 = 495 
[164] 328 + 617 = 945 
[165] 329 + 157 = 486 
[166] 329 + 517 = 846 
[167] 341 + 586 = 927 
[168] 342 + 576 = 918 
[169] 346 + 572 = 918 
[170] 346 + 581 = 927 
[171] 348 + 219 = 567 
[172] 349 + 218 = 567 
[173] 351 + 297 = 648 
[174] 352 + 467 = 819 
[175] 354 + 618 = 972 
[176] 354 + 627 = 981 
[177] 357 + 129 = 486 
[178] 357 + 291 = 648 
[179] 357 + 462 = 819 
[180] 357 + 624 = 981 
[181] 358 + 614 = 972 
[182] 359 + 127 = 486 
[183] 362 + 187 = 549 
[184] 362 + 457 = 819 
[185] 364 + 527 = 891 
[186] 367 + 128 = 495 
[187] 367 + 182 = 549 
[188] 367 + 452 = 819 
[189] 367 + 524 = 891 
[190] 368 + 127 = 495 
[191] 372 + 546 = 918 
[192] 376 + 218 = 594 
[193] 376 + 542 = 918 
[194] 378 + 216 = 594 
[195] 381 + 294 = 675 
[196] 381 + 546 = 927 
[197] 382 + 167 = 549 
[198] 382 + 194 = 576 
[199] 384 + 192 = 576 
[200] 384 + 291 = 675 
[201] 386 + 541 = 927 
[202] 387 + 162 = 549 
[203] 391 + 257 = 648 
[204] 391 + 284 = 675 
[205] 392 + 184 = 576 
[206] 394 + 182 = 576 
[207] 394 + 281 = 675 
[208] 397 + 251 = 648 
[209] 415 + 278 = 693 
[210] 418 + 239 = 657 
[211] 418 + 275 = 693 
[212] 419 + 238 = 657 
[213] 428 + 139 = 567 
[214] 429 + 138 = 567 
[215] 438 + 129 = 567 
[216] 438 + 219 = 657 
[217] 439 + 128 = 567 
[218] 439 + 218 = 657 
[219] 452 + 187 = 639 
[220] 452 + 367 = 819 
[221] 457 + 182 = 639 
[222] 457 + 362 = 819 
[223] 462 + 357 = 819 
[224] 467 + 352 = 819 
[225] 475 + 218 = 693 
[226] 478 + 215 = 693 
[227] 482 + 157 = 639 
[228] 482 + 193 = 675 
[229] 483 + 192 = 675 
[230] 487 + 152 = 639 
[231] 492 + 183 = 675 
[232] 493 + 182 = 675 
[233] 514 + 269 = 783 
[234] 517 + 329 = 846 
[235] 519 + 264 = 783 
[236] 519 + 327 = 846 
[237] 524 + 367 = 891 
[238] 527 + 319 = 846 
[239] 527 + 364 = 891 
[240] 529 + 317 = 846 
[241] 541 + 296 = 837 
[242] 541 + 386 = 927 
[243] 542 + 196 = 738 
[244] 542 + 376 = 918 
[245] 543 + 186 = 729 
[246] 543 + 276 = 819 
[247] 546 + 183 = 729 
[248] 546 + 192 = 738 
[249] 546 + 273 = 819 
[250] 546 + 291 = 837 
[251] 546 + 372 = 918 
[252] 546 + 381 = 927 
[253] 564 + 219 = 783 
[254] 564 + 327 = 891 
[255] 567 + 324 = 891 
[256] 569 + 214 = 783 
[257] 571 + 293 = 864 
[258] 572 + 346 = 918 
[259] 573 + 246 = 819 
[260] 573 + 291 = 864 
[261] 576 + 243 = 819 
[262] 576 + 342 = 918 
[263] 581 + 346 = 927 
[264] 583 + 146 = 729 
[265] 586 + 143 = 729 
[266] 586 + 341 = 927 
[267] 591 + 246 = 837 
[268] 591 + 273 = 864 
[269] 592 + 146 = 738 
[270] 593 + 271 = 864 
[271] 596 + 142 = 738 
[272] 596 + 241 = 837 
[273] 614 + 259 = 873 
[274] 614 + 358 = 972 
[275] 617 + 328 = 945 
[276] 618 + 327 = 945 
[277] 618 + 354 = 972 
[278] 619 + 254 = 873 
[279] 624 + 159 = 783 
[280] 624 + 357 = 981 
[281] 627 + 318 = 945 
[282] 627 + 354 = 981 
[283] 628 + 317 = 945 
[284] 629 + 154 = 783 
[285] 634 + 158 = 792 
[286] 634 + 257 = 891 
[287] 637 + 254 = 891 
[288] 638 + 154 = 792 
[289] 642 + 195 = 837 
[290] 643 + 275 = 918 
[291] 645 + 192 = 837 
[292] 645 + 273 = 918 
[293] 654 + 129 = 783 
[294] 654 + 138 = 792 
[295] 654 + 219 = 873 
[296] 654 + 237 = 891 
[297] 654 + 318 = 972 
[298] 654 + 327 = 981 
[299] 657 + 234 = 891 
[300] 657 + 324 = 981 
[301] 658 + 134 = 792 
[302] 658 + 314 = 972 
[303] 659 + 124 = 783 
[304] 659 + 214 = 873 
[305] 671 + 283 = 954 
[306] 673 + 245 = 918 
[307] 673 + 281 = 954 
[308] 675 + 243 = 918 
[309] 681 + 273 = 954 
[310] 683 + 271 = 954 
[311] 692 + 145 = 837 
[312] 695 + 142 = 837 
[313] 715 + 248 = 963 
[314] 716 + 238 = 954 
[315] 718 + 236 = 954 
[316] 718 + 245 = 963 
[317] 725 + 139 = 864 
[318] 729 + 135 = 864 
[319] 735 + 129 = 864 
[320] 735 + 246 = 981 
[321] 736 + 218 = 954 
[322] 736 + 245 = 981 
[323] 738 + 216 = 954 
[324] 739 + 125 = 864 
[325] 745 + 218 = 963 
[326] 745 + 236 = 981 
[327] 746 + 235 = 981 
[328] 748 + 215 = 963 
[329] 752 + 184 = 936 
[330] 754 + 182 = 936 
[331] 762 + 183 = 945 
[332] 763 + 182 = 945 
[333] 782 + 154 = 936 
[334] 782 + 163 = 945 
[335] 783 + 162 = 945 
[336] 784 + 152 = 936