結果
| 問題 |
No.222 引き算と足し算
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-06-06 01:32:06 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 753 bytes |
| コンパイル時間 | 638 ms |
| コンパイル使用メモリ | 58,332 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-15 21:30:28 |
| 合計ジャッジ時間 | 1,668 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:45:21: warning: ‘a’ may be used uninitialized in this function [-Wmaybe-uninitialized]
45 | ans = a - b;
| ~~~~^~~~~~~
ソースコード
#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 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;
now = "";
m = false;
cnt = 0;
op.append(1, s.at(i));
}else{
if(s.at(i) == '-') m = true;
}
}else{
now.append(1, s.at(i));
cnt++;
}
}
ans = sstoii(now);
if(m) ans *= -1;
b = ans;
if(op == "+")
ans = a - b;
if(op == "-")
ans = a + b;
printf("%d\n", ans);
return 0;
}