結果
問題 | No.539 インクリメント |
ユーザー |
![]() |
提出日時 | 2017-06-30 22:50:21 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 56 ms / 2,000 ms |
コード長 | 1,615 bytes |
コンパイル時間 | 1,302 ms |
コンパイル使用メモリ | 161,904 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-04 20:50:07 |
合計ジャッジ時間 | 1,955 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define FOR(i,a,b) for(int i=(a);i<(b);i++)#define REP(i,n) FOR(i,0,n)#define ALL(v) (v).begin(),(v).end()#define fi first#define se secondtemplate<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }typedef long long ll;typedef pair<int, int> pii;typedef pair<ll, ll> pll;typedef pair<int, pll> pip;const ll INF = 1ll<<29;const ll MOD = 1000000007;const double EPS = 1e-9;string sum(string a, string b) {if (a.size() > b.size()) swap(a, b);reverse(a.begin(), a.end());reverse(b.begin(), b.end());string res = "";int c = 0;REP(i, a.size()) {c += a[i] - '0' + b[i] - '0';res.push_back(c % 10 + '0');c /= 10;}FOR(i, a.size(), b.size()) {c += b[i] - '0';res.push_back(c % 10 + '0');c /= 10;}if (c > 0) res.push_back(c + '0');reverse(res.begin(), res.end());return res;}int main() {int T;cin >> T; cin.ignore();while (T--) {string S;getline(cin, S);int p[10];memset(p, -1, sizeof(p));REP(i, 10) {if (S.rfind(i + '0') == string::npos) continue;p[i] = S.rfind(i + '0');}int r = -1;REP(i, 10) chmax(r, p[i]);if (r == -1) {cout << S << endl;continue;}int l = r;while (l >= 0 && isdigit(S[l])) l--;l++;string ans = S.substr(0, l);string num = sum(S.substr(l, r - l + 1), "1");ans += num;ans += S.substr(r + 1, S.size());cout << ans << endl;}return 0;}