結果
| 問題 |
No.222 引き算と足し算
|
| コンテスト | |
| ユーザー |
TLwiegehtt
|
| 提出日時 | 2015-07-13 00:01:58 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 629 bytes |
| コンパイル時間 | 635 ms |
| コンパイル使用メモリ | 20,352 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-15 21:59:30 |
| 合計ジャッジ時間 | 1,355 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 WA * 12 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:10:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | scanf("%s", s);
| ^~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
int main(void){
int pos=0;
int mul = 0;
int sum = 0;
char symbol = '+';
char s[20];
scanf("%s", s);
if(s[0] == '-'){
symbol = '-';
pos++;
}else if(s[0] == '+'){
pos++;
}
for( ; s[pos] != '\0' ; pos++ ){
if( '0' <= s[pos] && s[pos] <= '9' ){
int num = (int)(s[pos] - '0');
mul = mul * 10 + num;
}else{
if(symbol == '+'){
sum += mul;
mul = 0;
}else{
sum -= mul;
mul = 0;
}
if(s[pos] == '+'){
symbol = '-';
}else{
symbol = '+';
}
}
}
if(symbol == '+'){
sum += mul;
}else{
sum -= mul;
}
printf("%d\n", sum);
return 0;
}
TLwiegehtt