結果
| 問題 |
No.539 インクリメント
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-07-01 01:16:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,675 bytes |
| コンパイル時間 | 1,071 ms |
| コンパイル使用メモリ | 68,308 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-04 23:17:25 |
| 合計ジャッジ時間 | 1,242 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | AC * 2 WA * 1 |
ソースコード
#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(true){
maxcnt = cnt;
maxind = ind;
}
cnt = 0;
}
}
if(true){
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;
}