結果
| 問題 |
No.193 筒の数式
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2015-06-14 18:17:15 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,536 bytes |
| コンパイル時間 | 574 ms |
| コンパイル使用メモリ | 84,544 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-06 20:15:59 |
| 合計ジャッジ時間 | 1,217 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:27: warning: ‘ans’ may be used uninitialized in this function [-Wmaybe-uninitialized]
18 | #define P(p) std::cout<<(p)<<std::endl;
| ^
main.cpp:36:13: note: ‘ans’ was declared here
36 | int ans;
| ^~~
ソースコード
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <list>
#include <queue>
#include <vector>
#include <complex>
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) std::cout<<(p)<<std::endl;
/////////
typedef long long LL;
typedef long double LD;
/////////
using namespace::std;
/////////
int main(void){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
std::cout << std::fixed;//
//cout << setprecision(6);//
string S;
cin>>S;
bool flag = false;
int ans;
int Max = S.size();
int temp = 0;
int tempAns = 0;
int mode = 0;
for(int i=0;i<Max;++i){
temp = 0;
tempAns = 0;
mode = 0;
for(int k=0;k<Max;++k){
if( S[ (i+k)%Max ] == '+'){
if(k==0 || k==(Max-1)){break;}
mode = 1;
}else
if( S[ (i+k)%Max ] == '-'){
if(k==0 || k==(Max-1)){break;}
mode = -1;
}
else{
temp = temp * 10 + S[ (i+k)%Max ] - '0';
if(k==(Max-1)){
if( mode == 1){
tempAns += temp;
}
else if( mode == -1){
tempAns -= temp;
}
if(flag == false){
ans = tempAns;
flag = true;
}else{
ans = ans>tempAns?ans:tempAns;
}
}
else if(S[ (i+k+1)%Max ] == '+' || S[ (i+k+1)%Max ] == '-'){
if( mode == 1){
tempAns += temp;
}
else if( mode == -1){
tempAns -= temp;
}
else if(mode == 0){
tempAns = temp;
}
temp = 0;
}
}
}
}
P(ans);
return 0;
}
IL_msta