結果

問題 No.193 筒の数式
ユーザー WinField95WinField95
提出日時 2015-04-26 22:38:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,251 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 81,532 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 12:09:25
合計ジャッジ時間 1,763 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<sstream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
// #define DEBUG

using namespace std;

// typedef pair<int,int>P;
// typedef complex<double>P;

typedef long long int ll;
typedef unsigned long long int ull;

const int INF = 1e9;
const double EPS=1e-9;

int calc(string str){
  if(!isdigit(str[0]))return -INF;
  if(!isdigit(str[str.size()-1]))return -INF;
  vector<int>vec;
  vector<char>ope;
  bool flag = false;
  stringstream s;
  s << str;
  while(!s.eof()){
    if(flag){
      char c;
      s >> c;
      ope.push_back(c);
      flag = false;
    }
    else {
      int num;
      s >> num;
      vec.push_back(num);
      flag = true;
    }
  }

  int ret = vec[0];
  for(int i = 0 ; i < ope.size() ; i++){
    if(ope[i] == '+')ret += vec[i+1];
    else ret -= vec[i+1];
  }
  return ret;
}

int main(int argc, char *argv[])
{
  string s;
  cin >> s;
  int res = -INF;
  for(int i = 0 ; i < s.size() ; i++){
    string tmp;
    for(int j = i ;  ; j = (j + 1)%s.size() ){
      tmp += s[j];
      if(j == (i + (int)s.size() -1)%s.size())break;
    }
    res = max(res,calc(tmp));
  }
  cout << res << endl;
  return 0;
}
0