結果

問題 No.207 世界のなんとか
ユーザー FF256grhyFF256grhy
提出日時 2015-05-17 17:15:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,103 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 26,720 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-20 09:26:36
合計ジャッジ時間 8,124 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,376 KB
testcase_16 WA -
testcase_17 OLE -
testcase_18 OLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

void align(char[]);
int is_aho(char[]);
void increment(char[]);
int neq(char[], char[]);
void print(char[]);

char a[11], b[11]; // 10桁 + 終端文字

int main(void) {
	scanf("%s %s", a, b);
	align(a);
	align(b);
	do {
		if( is_aho(a) ) { print(a); }
		increment(a);
	} while( neq(a, b) ); 
	return 0;
}

void align(char s[]) { // 繰り上がりがだるいので0詰めして右揃え
	int i = 0;
	while(s[i] != '\0') { i++; }
	int j;
	for(j = 10; 0 <= j; j--, i--) { // '\0' もコピー
		s[j] = i < 0 ? '0' : s[i];
	}
	return;
}

int is_aho(char s[]) {
	int i, sum = 0;
	for(i = 0; i < 10; i++) {
		if(s[i] == '3') { return 1; }
		sum += s[i] - '0';
	}
	return sum % 3 == 0;
}

void increment(char s[]) {
	int i = 9;
	while(s[i] == '9') {
		s[i] = '0';
		i--;
	}
	s[i]++;
	return;
}

int neq(char s[], char t[]) {
	int i;
	for(i = 0; i < 10; i++) {
		if(s[i] != t[i]) { return 1; }
	}
	return 0;
}

void print(char s[]) { // 0詰めしちゃったせいでそのまま表示できないのだ……
	int i = 0;
	while(s[i] == '0') { i++; }
	printf("%s\n", a + i);
	return;
}
0