Submission #00114
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | #include<bits/stdc++.h> using namespace std; int n; char s[1000][1000]; int memo[1000][1000][2]; int solve( int i, int j, char c){ int ret=-1; if (s[i][j] == '.' ){ return solve(i+1,j,c); } if (s[i][j] == '!' && s[i-1][j] != '.' ){ return 0; } else if (s[i][j] == '!' && s[i-1][j] == '.' ){ return 0; } if (c == '"' && '0' <= s[i][j] && s[i][j] <= '9' ){ return s[i][j] - '0' ; } if ((s[i][j] == '+' || s[i][j] == '*' ) && c == '"' ){ return solve(i+1,j+1,s[i][j]); } if ((s[i][j] == '+' || s[i][j] == '*' ) && c == '+' ){ return solve(i+1,j+1,s[i][j]) + solve(i+1,j, '+' ); } if ((s[i][j] == '+' || s[i][j] == '*' ) && c == '*' ){ return solve(i+1,j+1,s[i][j]) * solve(i+1,j, '*' ); } if ( '0' <= s[i][j] && s[i][j] <= '9' && c == '+' ){ //cout << "HA"<<endl; //cout << s[i][j] - '0'; return (s[i][j] - '0' ) + solve(i+1,j, '+' ); } if ( '0' <= s[i][j] && s[i][j] <= '9' && c == '*' ){ return (s[i][j] - '0' ) * solve(i+1,j, '+' ); } } int main(){ while (1){ cin>>n; if (n == 0) break ; memset (s, '!' , sizeof (s)); for ( int i=0;i<n;i++){ cin>>s[i]; } for ( int i=0;i<n;i++){ int j=0; while (1){ if (s[i][j] == '\0' ){ s[i][j] = '!' ; break ; } j++; } } cout<<solve(0,0, '"' )<<endl; } } |
ステータス
項目 | データ |
---|---|
問題 | 0003 - ICPC計算機 |
ユーザー名 | ei1437 |
投稿日時 | 2016-03-30 15:56:20 |
言語 | C++ |
状態 | Wrong Answer |
得点 | 0 |
ソースコード長 | 1349 Byte |
最大実行時間 | 21 ms |
最大メモリ使用量 | 3176 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 0 / 20 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
C1 | WA | 15 ms | 3164 KB |
1
|
C2 | WA | 16 ms | 3176 KB |
1
|
C3 | WA | 18 ms | 3056 KB |
1
|
C4 | WA | 21 ms | 2944 KB |
1
|