結果

問題 No.432 占い(Easy)
ユーザー dsytk7
提出日時 2016-10-14 22:56:10
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 889 bytes
コンパイル時間 2,714 ms
コンパイル使用メモリ 160,852 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-22 08:30:33
合計ジャッジ時間 3,168 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int ctoi(char c) {
    return c - '0';
}

string itos(int i) {
    ostringstream s;
    s << i;
    return s.str();
}

int main() {
    int n;
    cin >> n;

    while (n--) {

        string s;
        cin >> s;

        if (s.length() == 1) {
            cout << s << endl;
        }
        else {
            string t = "";
            while (s.length() > 1) {
                for (int i = 0; i < s.length()-1; ++i) {
                    int tmp = ctoi(s[i])+ctoi(s[i+1]);
                    if (tmp >= 10) {
                        t += itos(ctoi(itos(tmp)[0])+ctoi(itos(tmp)[1]));
                    }
                    else {
                        t += itos(tmp);
                    }
                }
                s = t;
                t = "";
            }
            cout << s << endl;
        }
    }
    return 0;
}
0