結果
| 問題 |
No.505 カードの数式2
|
| コンテスト | |
| ユーザー |
shiboy_AAA
|
| 提出日時 | 2017-04-21 23:09:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,134 bytes |
| コンパイル時間 | 542 ms |
| コンパイル使用メモリ | 54,648 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 15:15:59 |
| 合計ジャッジ時間 | 1,460 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 WA * 16 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:50:9: warning: ‘flag’ may be used uninitialized in this function [-Wmaybe-uninitialized]
50 | if (i == flag) total = total - a[i];
| ^~
ソースコード
#include <iostream>
using namespace std;
int main(){
int N, a[16];
int cnt=0;
int flag;
cin >> N;
for (int i=0; i<N; i++) cin >> a[i];
int total = a[0];
for (int i=0; i<N; i++){
if (a[i] < 0){
flag = i;
break;
}
}
for (int i=0; i<N; i++){
if (a[i] <= -2) cnt++;
}
cnt = cnt % 2;
if (cnt == 0){
for (int i=1; i<N; i++){
if ((a[i] == 0)||(a[i] == 1)){
total = total + a[i];
}
else if (a[i] >= 2){
if (total == 0) total = total + a[i];
else total = total * a[i];
}
else if (a[i] == -1){
total = total - a[i];
}
else {
if (total == 0) total = total - a[i];
else total = total * a[i];
}
}
}
else if (cnt == 1){
for (int i=1; i<N; i++){
if ((a[i] == 0)||(a[i] == 1)){
total = total + a[i];
}
else if (a[i] >= 2){
if (total == 0) total = total + a[i];
else total = total * a[i];
}
else {
if (i == flag) total = total - a[i];
else total = total * a[i];
}
}
}
cout << total << endl;
return 0;
}
shiboy_AAA