結果

問題 No.539 インクリメント
ユーザー masastatmasastat
提出日時 2017-07-01 00:56:13
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,693 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 67,888 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 07:45:10
合計ジャッジ時間 1,410 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#define MP make_pair
using ll = long long;
using namespace std;

int main()
{
  int T;
  cin >> T;
  vector<string>S(T);
  getline(cin,S[0]);
  for(int i=0; i < T; i++)
    getline(cin, S[i]);
  for(int i=0; i < T; i++){
    int ind = 0;
    int maxind = 0;
    int cnt = 0;
    int maxcnt = 0;
    for(int j=0; j < S[i].size(); j++){
      if(S[i][j] == '0' || S[i][j] == '1' || S[i][j] == '2' || S[i][j] == '3' || S[i][j] == '4' || S[i][j] == '5' || S[i][j] == '6' || S[i][j] == '7' || S[i][j] == '8' || S[i][j] == '9'){
        if(cnt == 0)
	  ind = j;
	cnt++;
      }else{
	if(cnt >= maxcnt){
	  maxcnt = cnt;
	  maxind = ind;
	}
	cnt = 0;
      }
    }
      if(cnt >= maxcnt){
	maxcnt = cnt;
	maxind = ind;
      }
      //cout << maxcnt << endl;
      //cout << maxind << endl;
      if(maxind >= 0 && maxcnt > 0){
      if(S[i][maxind+maxcnt-1] != '9'){
	int last_num = (int)(S[i][maxind+maxcnt-1]);
	last_num++;
	S[i][maxind+maxcnt-1] = (char)(last_num);
      }else if(S[i][maxind+maxcnt-1] == '9'){
	for(int k=maxind+maxcnt-1; k >= maxind; k--){
	  int n = (int)S[i][k];
	  //cout << S[i][k] << endl;
	  //cout << n << endl;
	  if(k == maxind && n == (int)'9'){
	    S[i][k] = '0';
	    string news(S[i].size()+1, 'a');
	    for(int l=0; l < maxind; l++)
	      news[l] = S[i][l];
	    news[maxind] = '1';
	    for(int l=maxind; l < S[i].size(); l++)
	      news[l+1] = S[i][l];
	    S[i] = news;
	  }else if(n != (int)'9'){
	    n++;
	    S[i][k] = (char)n;
	    break;
	  }else{
	    S[i][k] = '0';
	  }
	}
      }
     }
    cout << S[i] << endl;
  }

  return 0;
}
0