結果
問題 | No.116 門松列(1) |
ユーザー |
|
提出日時 | 2018-03-14 21:25:04 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 922 bytes |
コンパイル時間 | 17,656 ms |
コンパイル使用メモリ | 240,096 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 01:38:39 |
合計ジャッジ時間 | 17,425 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
package main import ( "bufio" "fmt" "os" "strconv" "strings" ) // エントリポイント func main() { in := bufio.NewScanner(os.Stdin) // 竹の数 in.Scan() input1 := in.Text() // 竹の高さ in.Scan() input2 := in.Text() fmt.Println(pineDecoration(input1, input2)) } // 竹の高さが門松の列になっている個数を返す。 func pineDecoration(bambooNum string, bambooHeights string) string { _ = bambooNum sp := strings.Split(bambooHeights, " ") h := make([]int, 0) for _, c := range sp { i, _ := strconv.Atoi(c) h = append(h, i) } // 門松の判定 count := 0 for i := 1; i < len(h)-1; i++ { // すべて違う高さ if h[i-1] == h[i] || h[i] == h[i+1] || h[i-1] == h[i+1] { continue } // 中央が2番目の高さではない if (h[i-1] > h[i] && h[i] > h[i+1]) || (h[i-1] < h[i] && h[i] < h[i+1]) { continue } count++ } return strconv.Itoa(count) }