結果

問題 No.432 占い(Easy)
ユーザー mmn15277198mmn15277198
提出日時 2020-12-27 20:28:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,118 bytes
コンパイル時間 818 ms
コンパイル使用メモリ 97,860 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-09 19:34:08
合計ジャッジ時間 1,731 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 9 ms
6,944 KB
testcase_13 AC 9 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 6 ms
6,940 KB
testcase_18 AC 6 ms
6,944 KB
testcase_19 AC 4 ms
6,940 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 3 ms
6,944 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<numeric>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

//const ll mod = 1000000007;
const ll mod = 998244353;
const ld pi = 3.14159265358979;

vector<int> ans;

int calc(int x){
  int sum = 0;
  while(x > 0){
    sum += x % 10;
    x /= 10;
  }
  return sum;
}

int solver(){
  string s;
  cin >> s;
  while(s.size() > 1){
    string t;
    for(int i = 0; i < s.size() - 1; i++){
      int now = int(s[i] - '0') + int(s[i + 1] - '0');
      if(now < 10){
        t += to_string(now);
      }else{
        t += to_string(calc(now));
      }
    }
    s = t;
  }
  return int(s[0] - '0');
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(15);
  int t;
  cin >> t;
  for(int i = 0; i < t; i++){
    ans.push_back(solver());
  }
  for(int i = 0; i < t; i++){
    cout << ans[i] << '\n';
  }
  return 0;
}
0