結果
| 問題 | No.539 インクリメント |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-20 23:15:50 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 190 ms / 2,000 ms |
| コード長 | 1,287 bytes |
| 記録 | |
| コンパイル時間 | 723 ms |
| コンパイル使用メモリ | 73,584 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-12-20 23:15:53 |
| 合計ジャッジ時間 | 2,657 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | scanf("%d", &t);
| ~~~~~^~~~~~~~~~
ソースコード
#include <iostream>
#include <vector>
using namespace std;
int t;
string s;
vector<int> vec;
int main() {
// freopen("string.in", "r", stdin);
// freopen("string.out", "w", stdout);
scanf("%d", &t);
getline(cin, s);
while (t--) {
getline(cin, s);
s = ' ' + s;
int l = 0, r = 0;
for (int i = s.size() - 1; i >= 1; --i) {
if (isdigit(s[i])) {
r = i;
break;
}
}
l = r;
for (int i = r - 1; i >= 1; --i) {
if (isdigit(s[i])) {
l = i;
} else {
break;
}
}
if (l == 0 && r == 0) {
cout << s.substr(1) << endl;
continue;
}
cout << s.substr(1, l - 1);
vec.clear();
for (int i = l; i <= r; ++i) vec.push_back(s[i] - '0');
int threshold = 1;
for (int i = vec.size() - 1; i >= 0; --i) {
vec[i] += threshold;
threshold = vec[i] / 10;
vec[i] %= 10;
}
if (threshold != 0) printf("%d", threshold);
for (int i = 0; i < vec.size(); ++i) printf("%d", vec[i]);
cout << s.substr(r + 1, s.size() - r - 1) << endl;
}
return 0;
}