結果
| 問題 | 
                            No.49 算数の宿題
                             | 
                    
| コンテスト | |
| ユーザー | 
                             subsn
                         | 
                    
| 提出日時 | 2023-06-13 09:43:45 | 
| 言語 | C  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1 ms / 5,000 ms | 
| コード長 | 999 bytes | 
| コンパイル時間 | 346 ms | 
| コンパイル使用メモリ | 29,696 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-12 21:53:38 | 
| 合計ジャッジ時間 | 1,223 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 10 | 
ソースコード
#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 = 1;
			nowNum = 0;
			continue;
		}
		nowNum = nowNum * 10 + (str[i] - '0');
		
	}
	if (nowSym == 0) {
		ans += nowNum;
	}
	else {
		ans *= nowNum;
	}
	printf("%d\n",ans);
}
            
            
            
        
            
subsn