結果
問題 | No.539 インクリメント |
ユーザー |
![]() |
提出日時 | 2017-08-04 00:44:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 1,500 bytes |
コンパイル時間 | 1,903 ms |
コンパイル使用メモリ | 167,248 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-11 20:38:03 |
合計ジャッジ時間 | 2,501 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define fst(t) std::get<0>(t)#define snd(t) std::get<1>(t)#define thd(t) std::get<2>(t)using ll = long long;using P = std::tuple<int,int>;const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};int main(){std::cin.tie(nullptr);std::ios::sync_with_stdio(false);int N;std::cin >> N;std::cin.ignore();for(int _=0;_<N;++_){std::string S;std::getline(std::cin, S);int first = -1, end = 0;for(int i=0,j=0;i<S.size();i=j){while(j < S.size() && !std::isdigit(S[j])){++j;}if(j == S.size()){break;}first = j;while(j < S.size() && std::isdigit(S[j])){++j;}end = j;}if(first == -1){std::cout << S << std::endl;return 0;}for(int i=0;i<first;++i){std::cout << S[i];}S[end-1] += 1;bool carry = false;for(int i=end-1;i>=first;--i){if(S[i] > '9'){if(i == first){carry = true;}else{S[i-1] += 1;}S[i] -= 10;}else{break;}}if(carry){std::cout << 1;}for(int i=first;i<S.size();++i){std::cout << S[i];}std::cout << std::endl;}}