結果
| 問題 |
No.49 算数の宿題
|
| コンテスト | |
| ユーザー |
kapo
|
| 提出日時 | 2016-05-31 11:05:10 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 517 bytes |
| コンパイル時間 | 601 ms |
| コンパイル使用メモリ | 56,024 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-23 01:51:40 |
| 合計ジャッジ時間 | 1,191 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
string S;
cin >> S;
int k1 = 0, k2 = k1;
while('0' <= S[k2] && S[k2] <= '9' ) k2++;
int ans = stoi(S.substr(k1, k2));
k1 = k2;
k2++;
while(k1 < S.size()) {
if(S[k1] == '+') {
while('0' <= S[k2] && S[k2] <= '9' ) k2++;
ans *= stoi(S.substr(k1+1, k2));
} else if(S[k1] == '*') {
while('0' <= S[k2] && S[k2] <= '9' ) k2++;
ans += stoi(S.substr(k1+1, k2));
}
k1 = k2;
k2++;
}
cout << ans << endl;
return 0;
}
kapo