結果
| 問題 |
No.49 算数の宿題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-02-22 00:36:38 |
| 言語 | Go (1.23.4) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 849 bytes |
| コンパイル時間 | 14,699 ms |
| コンパイル使用メモリ | 217,600 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-23 01:49:41 |
| 合計ジャッジ時間 | 15,548 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
var sc = bufio.NewScanner(os.Stdin)
func main() {
sc.Split(bufio.ScanWords)
s := nextLine()
s = strings.Replace(s, "*", " * ", -1)
s = strings.Replace(s, "+", " + ", -1)
expr := strings.Split(s, " ")
n, _ := strconv.Atoi(expr[0])
for i := 1; i < len(expr)-1; i += 2 {
v, _ := strconv.Atoi(expr[i+1])
switch expr[i] {
case "*":
n += v
case "+":
n *= v
}
}
fmt.Println(n)
}
func nextLine() string {
sc.Scan()
return sc.Text()
}
func nextInt() int {
i, _ := strconv.Atoi(nextLine())
return i
}
func nextInt64() int64 {
i, _ := strconv.ParseInt(nextLine(), 10, 64)
return i
}
func nextUint64() uint64 {
i, _ := strconv.ParseUint(nextLine(), 10, 64)
return i
}
func nextFloat() float64 {
f, _ := strconv.ParseFloat(nextLine(), 64)
return f
}