結果
| 問題 |
No.222 引き算と足し算
|
| コンテスト | |
| ユーザー |
めうめう🎒
|
| 提出日時 | 2016-01-23 16:26:22 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 909 bytes |
| コンパイル時間 | 716 ms |
| コンパイル使用メモリ | 75,624 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-15 22:09:33 |
| 合計ジャッジ時間 | 1,680 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:57:24: warning: ‘n’ may be used uninitialized in this function [-Wmaybe-uninitialized]
57 | else cout << n-m << endl;
| ^
main.cpp:56:9: warning: ‘hugo’ may be used uninitialized in this function [-Wmaybe-uninitialized]
56 | if(hugo) cout << n+m << endl;
| ^~
ソースコード
#include <iostream>
#include <sstream>
#include <math.h>
#include <stack>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <cstdio>
#include <vector>
using namespace std;
#define INF (1 << 30)
#define INFLL (1LL << 60)
int sstoi(string a){
int n = 0;
bool flag = 0;
if(a[0] == '-'){
flag = 1;
a.erase(0,1);
}else if(a[0] == '+'){
a.erase(0,1);
}
for(int i = 0;i < a.size();i++){
n = n*10;
n += a[i] - '0';
}
if(flag) n = -n;
return n;
}
int main() {
bool hugo;
string str;
cin >> str;
string a = "";
int n,m;
a += str[0];
for(int i = 1;i < str.size();i++){
if(str[i] >= '0' && str[i] <= '9') {
a += str[i];
}else{
if(str[i] == '-') hugo = 1;
else hugo = 0;
n = sstoi(a);
a = "";
a += str[i+1];
i++;
}
}
m = sstoi(a);
if(hugo) cout << n+m << endl;
else cout << n-m << endl;
return 0;
}
めうめう🎒