結果
| 問題 |
No.49 算数の宿題
|
| コンテスト | |
| ユーザー |
subsn
|
| 提出日時 | 2023-06-13 09:42:28 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 999 bytes |
| コンパイル時間 | 944 ms |
| コンパイル使用メモリ | 29,184 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-12 21:51:18 |
| 合計ジャッジ時間 | 679 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 9 |
ソースコード
#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 == 0) {
ans += nowNum;
}
else {
ans *= nowNum;
}
printf("%d\n",ans);
}
subsn