結果
| 問題 |
No.539 インクリメント
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-11-20 12:57:54 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 2,000 ms |
| コード長 | 1,832 bytes |
| コンパイル時間 | 618 ms |
| コンパイル使用メモリ | 68,224 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-26 03:20:02 |
| 合計ジャッジ時間 | 1,501 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 |
ソースコード
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class Number
{
public:
string number;
Number(){}
Number(string num)
{
number = num;
}
Number& operator++()
{
size_t length = number.size();
for (int i = length - 1; i >= 0; --i)
{
number[i] = ((number[i] - '0') + 1) % 10 + '0';
if (number[i] != '0') break;
else if (i == 0) {
number = "1" + number;
}
}
return *this;
}
};
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
cin >> T;
string line;
getline(cin, line);
while(T--)
{
getline(cin, line);
string head = "";
string num = "";
string tail = "";
bool begin = false;
int lastIndexOfBegin = 0;
int firstIndexOfTail = line.length() - 1;
for(int i = line.length() - 1; i >= 0; --i)
{
if (line[i] >= '0' && line[i] <= '9')
{
if (!begin) firstIndexOfTail = i + 1;
begin = true;
}
else
{
if (!begin) continue;
lastIndexOfBegin = i + 1;
break;
}
}
if (lastIndexOfBegin == 0 && firstIndexOfTail == line.length() - 1)
{
cout << line << endl;
continue;
}
//cout << lastIndexOfBegin << " " << firstIndexOfTail << endl;
Number number(line.substr(lastIndexOfBegin, firstIndexOfTail - lastIndexOfBegin));
++number;
cout << line.substr(0, lastIndexOfBegin);
cout << number.number;
cout << line.substr(firstIndexOfTail, line.length() - firstIndexOfTail) << endl;
}
}