結果

問題 No.432 占い(Easy)
コンテスト
ユーザー SSRS
提出日時 2020-08-07 06:44:50
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 461 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 354 ms
コンパイル使用メモリ 74,992 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-10 19:53:30
合計ジャッジ時間 1,632 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <string>
using namespace std;
string f(string S){
	int N = S.size();
	if (N == 1){
		return S;
	} else {
		string ans;
		for (int i = 0; i < N - 1; i++){
			int a = S[i] - '0';
			int b = S[i + 1] - '0';
			if (a + b <= 9){
				ans += '0' + a + b;
			} else {
				ans += '0' + a + b - 9;
			}
		}
		return f(ans);
	}
}
int main(){
	int T;
	cin >> T;
	for (int i = 0; i < T; i++){
		string S;
		cin >> S;
		cout << f(S) << endl;
	}
}
0