結果

問題 No.222 引き算と足し算
ユーザー metasequo
提出日時 2015-06-06 00:37:17
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 804 bytes
コンパイル時間 735 ms
コンパイル使用メモリ 59,024 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-15 21:30:00
合計ジャッジ時間 1,464 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other AC * 2 WA * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:49:15: warning: ‘a’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |         printf("%d\n", a+b);
      |         ~~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int sstoii(std::string str){
	int ret;
	std::stringstream ss;
	ss << str;
	ss >> ret;
	return ret;
}

int main(){
	string s, op, now;
	int a, b, ans, cnt=0;
	bool f = false, p = false, m = false;
	cin >> s;

	for(int i = 0; i < s.size(); i++){
		if(s.at(i) == '+' || s.at(i) == '-'){
			if(cnt != 0){
				ans = sstoii(now);
				if(m)	ans *= -1;
				a = ans;
				p = false;
				m = false;
				f = true;
				cnt = 0;
			}else{
				if(!f){
					if(s.at(i) == '+')	p = true;
					if(s.at(i) == '-')	m = true;
				}else{
					op = s.at(i);
					f = false;
				}
			}
		}else{
			now.append(now.size(), s.at(i));
			cnt++;
		}
	}
	ans = sstoii(now);
	if(m)	ans *= -1;
	b = ans;

	printf("%d\n", a+b);
	return 0;
}
0