結果

問題 No.49 算数の宿題
ユーザー fmhrfmhr
提出日時 2016-07-09 05:23:32
言語 Go
(1.21.3)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 601 bytes
コンパイル時間 14,012 ms
コンパイル使用メモリ 209,456 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 17:32:58
合計ジャッジ時間 13,647 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var s, n string
	fmt.Scan(&s)
	sym := make([]int, 0)
	num := make([]int, 0)
	for i := 0; i < len(s); i++ {
		if s[i]=='*' {
			sym = append(sym, 1)
			i, _ := strconv.Atoi(n)
			num = append(num, i)
			n = ""
		}else if s[i]=='+'{
			sym = append(sym, 2)
			i, _ := strconv.Atoi(n)
			num = append(num, i)
			n = ""
		}else{
			n = n + string(s[i])
		}
	}
	i, _ := strconv.Atoi(n)
	num = append(num, i)
	ans := num[0]
	for i := 0; i < len(sym); i++ {
		if (sym[i]==1){
			ans += num[i+1]
		}else{
			ans *= num[i+1]
		}
	}
	fmt.Println(ans)
}
0