結果
| 問題 |
No.49 算数の宿題
|
| コンテスト | |
| ユーザー |
subsn
|
| 提出日時 | 2023-06-13 09:41:47 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 999 bytes |
| コンパイル時間 | 234 ms |
| コンパイル使用メモリ | 29,568 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-12 21:50:24 |
| 合計ジャッジ時間 | 860 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 WA * 7 |
ソースコード
#include <stdio.h>
#include <malloc.h>
#include <stdint.h>
char str[60000];
int str_len = 0;
/// <summary>
/// グローバル変数strの中身を入力された文字列で上書きする
/// </summary>
void ReadString() {
char c = getchar();
str_len = 0;
while (c != '\n') {
str[str_len] = c;
c = getchar();
str_len++;
}
}
int main()
{
ReadString();
int nowSym = -1;
int ans = 0;
int nowNum = 0;
for (int i = 0;i < str_len;i++) {
if (str[i] == '*') {
if (nowSym == -1) {
ans = nowNum;
}
else {
if (nowSym == 0) ans += nowNum;
if (nowSym == 1) ans *= nowNum;
}
nowSym = 0;
nowNum = 0;
continue;
}
if (str[i] == '+') {
if (nowSym == -1) {
ans = nowNum;
}
else {
if (nowSym == 0) ans += nowNum;
if (nowSym == 1) ans *= nowNum;
}
nowSym = 0;
nowNum = 0;
continue;
}
nowNum = nowNum * 10 + (str[i] - '0');
}
if (nowSym == 1) {
ans += nowNum;
}
else {
ans *= nowNum;
}
printf("%d\n",ans);
}
subsn