結果
問題 | No.49 算数の宿題 |
ユーザー |
![]() |
提出日時 | 2018-01-15 16:13:45 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,549 bytes |
コンパイル時間 | 918 ms |
コンパイル使用メモリ | 86,220 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 01:58:31 |
合計ジャッジ時間 | 1,431 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
#include <iostream>#include <vector>#include <string>#include <cstring>#include <math.h>#include <cmath>#include <limits.h>#include <map>#include <set>#include <queue>#include <algorithm>#include <functional>#include <stdio.h>using namespace std;long long MOD = 1000000007;vector<string> split(const string &str ){vector<string> v; // 分割結果を格納するベクターauto first = str.begin(); // テキストの最初を指すイテレータwhile( first != str.end() ) { // テキストが残っている間ループauto last = first; // 分割文字列末尾へのイテレータwhile( last != str.end() && isdigit( *last ) ) // 末尾 or セパレータ文字まで進める++last;v.push_back(string(first, last)); // 分割文字を出力if( last != str.end() )++last;first = last; // 次の処理のためにイテレータを設定}return v;}int main() {string S;cin >> S;vector<string> VS;VS = split( S );vector<int> V;for ( int i = 0; i < S.length(); i++ ) {if ( !isdigit(S[i]) ) {V.push_back( S[i] == '*' ? 1 : 0 );}}int ans = stoi( VS[0] );for ( int i = 1; i < VS.size(); i++ ) {int d = stoi( VS[i] );if ( V[i-1] ) { ans += d; }else { ans *= d; }}cout << ans << endl;return 0;}