結果

問題 No.434 占い
ユーザー kei
提出日時 2016-10-14 23:44:15
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 974 bytes
コンパイル時間 956 ms
コンパイル使用メモリ 99,060 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-11-22 06:58:49
合計ジャッジ時間 25,603 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20 TLE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>
#include<queue>
using namespace std;

int check(string s) {
	int f1, f2;
	queue<int> q;
	for (int i = 0; i < s.length();i++) {
		q.push(s[i] - '0');
	}
	int size = q.size();

	while (q.size() != 1) {
		//cout << q.size() << endl;
		if (size == 1) {
			q.pop();
			size = q.size();
			if (size == 1) break;
		}
		f1 = q.front(); q.pop();
		f2 = q.front();
		//cout << f1 << " " << f2 << " " << endl;
		if (f1 + f2 < 10) {
			q.push(f1 + f2);
		}
		else {
			q.push(1 + (f1 + f2) % 10);
		}
		size--;
	}
	return q.front();
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int T; cin >> T;
	vector<string> S(T);
	for (int i = 0; i < T; i++) {
		cin >> S[i];
	}
	for (int i = 0; i < T;i++) {
		cout << check(S[i]) << endl;
	}
	return 0;
}
0