結果
問題 | No.539 インクリメント |
ユーザー |
|
提出日時 | 2017-06-30 22:40:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 46 ms / 2,000 ms |
コード長 | 779 bytes |
コンパイル時間 | 578 ms |
コンパイル使用メモリ | 72,752 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-04 20:37:55 |
合計ジャッジ時間 | 1,387 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 |
ソースコード
#include <iostream>#include <algorithm>#include <string>#include <vector>#include <cctype>int main() {int T;std::cin >> T;std::cin.ignore();while (T--) {std::string s;std::getline(std::cin, s);int i = s.size() - 1;while (i >= 0 && !isdigit(s[i])) i--;int ii = i + 1;if (ii == 0) {std::cout << s << std::endl;continue;}while (i >= 0 && isdigit(s[i])) i--;i++;if (std::count(s.begin() + i, s.begin() + ii, '9') == ii - i) {s.erase(i, ii - i);s.insert(i, std::string(ii - i, '0'));s.insert(i, std::string(1, '1'));} else {int carry = 1;for (int j = ii - 1; j >= i; j--) {s[j] += carry;carry = (s[j] - '0') / 10;s[j] = (s[j] - '0') % 10 + '0';}}std::cout << s << std::endl;}}