結果

問題 No.207 世界のなんとか
ユーザー FF256grhy
提出日時 2015-05-17 17:15:14
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,103 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 23,296 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-06 05:04:13
合計ジャッジ時間 8,139 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 WA * 9 OLE * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         scanf("%s %s", a, b);
      |         ~~~~~^~~~~~~~~~~~~~~

ソースコード

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