結果

問題 No.193 筒の数式
ユーザー notetonousnotetonous
提出日時 2016-04-29 00:28:43
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 745 bytes
コンパイル時間 146 ms
コンパイル使用メモリ 25,536 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-27 18:17:05
合計ジャッジ時間 1,172 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 0 ms
4,376 KB
testcase_07 AC 0 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 0 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 0 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string.h>
int main(){
  char s[21];
  int i,j;
  int len;
  int ans;
  int max=-10000000;
  int x;
  int flag=0;//0 plus 1 minus
  int ch=1;
  scanf("%s",s);
  len=strlen(s);
  for(i=len;i<len+len-1;i++)s[i]=s[i-len];
  s[i]='\0';
  for(i=0;i<len;i++){
    x=0;ans=0;flag=0;ch=1;
    for(j=i;j<i+len;j++){
      if(s[i]=='+' ||  s[i]=='-' || s[i+len-1]=='+' || s[i+len-1]=='-') ch=0;
      else{
	if(s[j]=='+'){
	  if(flag==0)ans+=x;
	  else ans-=x;
	  x=0;flag=0;
	}
	else if(s[j]=='-'){
	  if(flag==0)ans+=x;
	  else ans-=x;
	  x=0;flag=1;
	}
	else x=x*10+(s[j]-48);
      }
    }
    if(ch==1){
      if(flag==0)ans+=x;
      else ans-=x;
      if(max < ans)max=ans;
    }
  }
  printf("%d\n",max);
  return 0;
}
0