結果
問題 |
No.3157 Nabeatsu
|
ユーザー |
![]() |
提出日時 | 2025-05-24 16:38:20 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 988 bytes |
コンパイル時間 | 734 ms |
コンパイル使用メモリ | 43,608 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-05-24 16:38:25 |
合計ジャッジ時間 | 3,555 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:47:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 47 | scanf("%s", s); | ~~~~~^~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 3157.cc: No.3157 Nabeatsu - yukicoder */ #include<cstdio> #include<cstring> #include<algorithm> using namespace std; /* constant */ const int MAX_L = 1000000; /* typedef */ /* global variables */ char s[MAX_L + 4]; /* subroutines */ void dec(int l, char s[]) { int co = 1; for (int i = l - 1; co && i >= 0; i--) { if (s[i] == '0') s[i] = '9'; else s[i]--, co = 0; } } int dig3(int l, char s[]) { for (int i = 0; i < l; i++) if (s[i] == '3') return i; return -1; } bool multiple3(int l, char s[]) { int sum = 0; for (int i = 0; i < l; i++) sum += (s[i] - '0'); return (sum % 3 == 0); } /* main */ int main() { scanf("%s", s); int l = strlen(s); for (;;) { //puts(s); int d3 = dig3(l, s); //printf(" d3=%d\n", d3); if (d3 >= 0) { s[d3] = '2'; for (int i = d3 + 1; i < l; i++) s[i] = '9'; } if (multiple3(l, s)) dec(l, s); else break; } puts(s); return 0; }