結果

問題 No.539 インクリメント
ユーザー beetbeet
提出日時 2017-06-30 22:38:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 641 bytes
コンパイル時間 1,247 ms
コンパイル使用メモリ 160,988 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-04-15 06:44:05
合計ジャッジ時間 2,101 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 41 ms
6,940 KB
testcase_02 AC 47 ms
6,940 KB
testcase_03 AC 48 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int T;
  cin>>T;
  cin.ignore();
  string s;
  while(T--){
    getline(cin,s);
    reverse(s.begin(),s.end());
    for(int i=0;i<(int)s.size();i++){
      if(!isdigit(s[i])) continue;
      int j=i;
      string t;
      while(j<(int)s.size()&&isdigit(s[j]))
	t+=s[j++];
      j=0;
      int len=t.size();
      while(j<(int)t.size()){
	if(t[j]=='9'){
	  t[j++]='0';
	  continue;
	}
	t[j]++;
	break;
      }
      if(j==(int)t.size()) t+="1";
      s.replace(i,len,t);
      break;
    }
    reverse(s.begin(),s.end());
    cout<<s<<endl;
  }
  return 0;
}
0