結果

問題 No.49 算数の宿題
ユーザー fmhrfmhr
提出日時 2016-07-09 05:32:57
言語 Go
(1.22.1)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 579 bytes
コンパイル時間 9,746 ms
コンパイル使用メモリ 200,976 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 17:33:15
合計ジャッジ時間 10,373 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 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]>= '0' && s[i]<='9'{
			n = n + string(s[i])
		}else{
			v, _ := strconv.Atoi(n)
			num = append(num, v)
			n = ""
			if s[i]=='*' {
				sym = append(sym, 1)
			}else if s[i]=='+'{
				sym = append(sym, 2)
			}
		}
	}
	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