結果
| 問題 | No.3157 Nabeatsu | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-05-24 19:57:27 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 27 ms / 2,000 ms | 
| コード長 | 710 bytes | 
| コンパイル時間 | 1,845 ms | 
| コンパイル使用メモリ | 195,760 KB | 
| 実行使用メモリ | 7,848 KB | 
| 最終ジャッジ日時 | 2025-05-24 19:57:32 | 
| 合計ジャッジ時間 | 4,488 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 45 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
bool is_nabeatsu(string N){
    int digitsum = 0;
    for (char c:N) digitsum += c - '0';
    return digitsum % 3 ==0 || find(N.begin(), N.end(), '3') != N.end();
}
int main(){
    string N;
    cin >> N;
    
    while (is_nabeatsu(N)){
        auto it = find(N.begin(), N.end(), '3');
        if (it == N.end()){
            for (int i = N.size() - 1;; i--){
                if (N[i] == '0') N[i] = '9';
                else{
                    N[i]--;
                    break;
                }
            }
        }
        else{
            *it = '2';
            while(++it != N.end()) *it = '9';
        }
    }
    cout << N << endl;
    return 0;
}
            
            
            
        