結果

問題 No.49 算数の宿題
コンテスト
ユーザー kotatsugame
提出日時 2026-04-02 00:48:17
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 395 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 390 ms
コンパイル使用メモリ 76,904 KB
実行使用メモリ 82,460 KB
最終ジャッジ日時 2026-04-02 00:48:36
合計ジャッジ時間 1,384 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<cassert>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	string S;cin>>S;
	int idx=0;
	auto val=[&]()
	{
		int ret=0;
		while('0'<=S[idx]&&S[idx]<='9')ret=ret*10+S[idx]-'0',idx++;
		return ret;
	};
	int ans=val();
	while(idx<S.size())
	{
		char op=S[idx++];
		int t=val();
		if(op=='+')ans*=t;
		else ans+=t;
	}
	cout<<ans<<endl;
}
0