結果
問題 | No.193 筒の数式 |
ユーザー | nablaenergy_21 |
提出日時 | 2015-04-26 22:46:09 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 894 bytes |
コンパイル時間 | 192 ms |
コンパイル使用メモリ | 27,176 KB |
実行使用メモリ | 4,500 KB |
最終ジャッジ日時 | 2023-09-18 12:17:15 |
合計ジャッジ時間 | 1,082 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 1 ms
4,380 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 1 ms
4,376 KB |
testcase_09 | AC | 2 ms
4,376 KB |
testcase_10 | AC | 1 ms
4,376 KB |
testcase_11 | AC | 1 ms
4,380 KB |
testcase_12 | AC | 2 ms
4,380 KB |
testcase_13 | AC | 1 ms
4,380 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
ソースコード
#include <stdio.h> #include <string.h> char S[21]; int M,ans; int max(int a,int b){ if(a>b){return a;}else{return b;} } int val(int a){ int v,t,s,i; char p; /*Sのa番目からM文字を読んで計算する*/ if(S[a] == '+' || S[a] == '-'){return -1;} if(S[a+M-1] == '+' || S[a+M-1] == '-'){return -1;} v = 0; t = 0; s = 1; for(i=a;i<a+M;i++){ p = S[i]; if(p=='+'){ if(s == 1){ v = v + t; }else{ v = v - t; } t = 0; s = 1; }else if(p=='-'){ if(s == 1){ v = v + t; }else{ v = v - t; } t = 0; s = -1; }else{ t = t * 10; t = t + (p - '0'); } } if(s == 1){ v = v + t; }else{ v = v - t; } t = 0; s = 1; return v; } int main(void){ int i; scanf("%s",S); M = strlen(S); for(i=M;i<2*M;i++){ S[i] = S[i-M]; } S[2*M] = '\0'; ans = 0; for(i=0;i<M;i++){ ans = max(ans,val(i)); } printf("%d\n",ans); }