結果
| 問題 |
No.539 インクリメント
|
| コンテスト | |
| ユーザー |
nanophoto12
|
| 提出日時 | 2017-08-17 09:48:07 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 363 ms / 2,000 ms |
| コード長 | 3,492 bytes |
| コンパイル時間 | 1,391 ms |
| コンパイル使用メモリ | 115,420 KB |
| 実行使用メモリ | 10,512 KB |
| 最終ジャッジ日時 | 2024-10-14 13:33:59 |
| 合計ジャッジ時間 | 3,144 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 |
ソースコード
#include <cmath>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>
#include <stack>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> t3;
struct parser
{
const string _s;
map<char,vector<int>> _m;
parser(string s) : _s(s)
{
for(int i = 0;i < s.length();i++)
{
_m[s[i]].push_back(i);
}
}
bool isNumeric(char c)
{
if(c >= '0' && c <= '9')
{
return true;
}
return false;
}
vector<pair<int,int>> getNumerics()
{
int i = (int)_s.length()-1;
bool searching = false;
int last = -1;
vector<pair<int,int>> v;
while(i >= 0)
{
if(!searching)
{
if(isNumeric(_s[i]))
{
searching = true;
last = i;
}
i--;
}
else if(!isNumeric(_s[i]))
{
searching = false;
v.push_back(make_pair(i + 1, last - (i+1) + 1));
i--;
}
else
{
i--;
}
}
if(searching)
{
v.push_back(make_pair(0, last + 1));
}
sort(v.begin(), v.end());
return v;
}
pair<int,int> getLast()
{
auto a = getNumerics();
for(auto e = a.rbegin();e != a.rend();e++)
{
return *e;
}
return make_pair(-1,-1);
}
pair<char, int> increment(char c, int up)
{
int i = c - '0';
i+=up;
if(i >= 10)
{
return make_pair(i-10 + '0', 1);
}
return make_pair(i + '0', 0);
}
pair<list<char>, pair<int,int>> getIncrement()
{
auto l = getLast();
if(l.first == -1)
{
return make_pair(list<char>(), l);
}
string tar = _s.substr(l.first, l.second);
list<char> v;
int up = 1;
for(int i = (int)tar.length()-1 ; i >= 0;i--)
{
auto next = increment(tar[i], up);
v.push_front(next.first);
up = next.second;
}
if(up)
{
v.push_front('1');
}
return make_pair(v, l);
}
string build()
{
auto g = getIncrement();
if((int)g.first.size() == 0)
{
return _s;
}
ostringstream ss;
for(int i = 0;i < _s.length();i++)
{
if(i >= g.second.first && i < g.second.first + g.second.second)
{
if(i == g.second.first)
{
for(auto c : g.first)
{
ss << c;
}
}
}
else
{
ss << _s[i];
}
}
return ss.str();
}
};
int main()
{
string tt;
getline(cin, tt);
int t = stoi(tt);
for(int i = 0;i < t;i++)
{
string s;
getline(cin, s);
parser p(s);
cout << p.build() << endl;
}
return 0;
}
nanophoto12