結果

問題 No.193 筒の数式
ユーザー 158b158b
提出日時 2015-05-25 14:49:41
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,398 bytes
コンパイル時間 754 ms
コンパイル使用メモリ 66,140 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 13:02:39
合計ジャッジ時間 1,549 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 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 2 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 2 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 1 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 -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int func(std::__cxx11::string)’:
main.cpp:25:13: warning: overflow in conversion from ‘long int’ to ‘int’ changes value from ‘-9223372036854775807’ to ‘1’ [-Woverflow]
     return -LONG_MAX;
             ^~~~~~~~
main.cpp:45:11: warning: overflow in conversion from ‘long int’ to ‘int’ changes value from ‘-9223372036854775807’ to ‘1’ [-Woverflow]
   return -LONG_MAX;
           ^~~~~~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <vector>
#include <numeric>
using namespace std;

int func(string a){
	long total = 0;
	long num = 0;
	bool flg = false;	//左の項が存在しているか。
	bool op = true;		//true足し算/false引き算
	for(int i=0; i<a.length(); i++){
		//数値が見つかった場合
		if(a[i] !=  '+' && a[i] != '-'){
			flg = true;
			num *= 10;
			num += a[i] - '0';
			
		//記号が見つかった場合
		}else{
			if(!flg){
				return -LONG_MAX;
			}else{
				if(op){
					total += num;
				}else{
					total -= num;
				}
				num = 0;
				flg = false;
				if(a[i] == '+'){
					op = true;
				}else{
					op = false;
				}
			}
		}
	}
	
	//最後の項が未処理
	if(!flg){
		return -LONG_MAX;
	}else{
		if(op){
			total += num;
		}else{
			total -= num;
		}
	}
	
	return total;
}


int main(){
	string data;
	long kekka;
	long ans = -LONG_MAX;
	char save;
	
	cin >> data;
	
	for(int i=0; i<data.length(); i++){
		//cout << "■" << data << endl;
		kekka = func(data);
		//cout << "result:" << kekka << endl;
		//ans更新
		if(kekka > ans){
			ans = kekka;
		}
		
		//文字列をずらす処理(左循環シフト)
		save = data[0];
		for(int ii=0; ii<data.length()-1; ii++){
			data[ii] = data[ii+1];
		}
		data[data.length() - 1] = save;
		
	}
	
	cout << ans << endl;
	return 0;
}
0