結果

問題 No.539 インクリメント
ユーザー kotatsugame
提出日時 2018-07-08 07:19:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 456 bytes
コンパイル時間 555 ms
コンパイル使用メモリ 67,564 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-06 13:54:59
合計ジャッジ時間 2,037 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:5:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    5 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
int t;
string s;
main()
{
	cin>>t;
	cin.ignore();
	for(;t--;)
	{
		getline(cin,s);
		int i=s.size()-1;
		while(i>=0&&!isdigit(s[i]))i--;
		if(i==-1)
		{
			cout<<s<<endl;
			continue;
		}
		while(1)
		{
			if(!isdigit(s[i]))
			{
				cout<<s.substr(0,i+1)<<"1"<<s.substr(i+1)<<endl;
				break;
			}
			s[i]++;
			if(s[i]>'9')
			{
				s[i]='0';
				i--;
			}
			else
			{
				cout<<s<<endl;
				break;
			}
		}
	}
}
0