結果

問題 No.207 世界のなんとか
ユーザー FF256grhy
提出日時 2015-05-17 17:19:37
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,113 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 23,296 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-09 10:15:01
合計ジャッジ時間 853 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
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);
	increment(b);
	while( neq(a, b) ) {
		if( is_aho(a) ) { print(a); }
		increment(a);
	}
	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