結果

問題 No.24 数当てゲーム
ユーザー yo-kondoyo-kondo
提出日時 2018-03-10 11:38:43
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,459 bytes
コンパイル時間 12,764 ms
コンパイル使用メモリ 206,548 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-03 07:15:26
合計ジャッジ時間 13,731 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

// エントリポイント
func main() {
	in := bufio.NewScanner(os.Stdin)
	in.Scan()
	input1 := in.Text()
	input2 := make([]string, 0)
	for in.Scan() {
		input2 = append(input2, in.Text())
	}

	fmt.Println(numbers(input1, input2))
}

// 思い浮かべた数を判定して返す
func numbers(line string, numList []string) string {
	_ = line

	// 0:初期値,1:NO,2:YES
	result := [10]int{}

	// 判定処理
	for _, v := range numList {
		sp := strings.Split(v, " ")
		strAry := sp[0:len(sp)-1]
		yesNo := sp[len(sp)-1]

		// strAryを数値に変換
		numAry := make([]int, 0)
		for _, v2 := range strAry {
			i, _ := strconv.Atoi(v2)
			numAry = append(numAry, i)
		}

		if yesNo == "NO" {
			for _, v2 := range numAry {
				 result[v2] = 1
			}
		}

		if yesNo == "YES" {
			// numAry にないものはすべて1
			for i3, v3 := range result {
				if v3 == 0 || v3 == 2 {
					if existAry(numAry, i3) {
						result[i3] = 2
					} else {
						result[i3] = 1
					}
				}
			}
		}
	}

	// 結果を探す
	for i3, v3 := range result {
		if v3 == 2 {
			return strconv.Itoa(i3)
		}
	}
	for i4, v4 := range result {
		if v4 == 0 {
			return strconv.Itoa(i4)
		}
	}

	// ここには来ないはず
	return ""
}

// 配列内に値があるか判定する。
func existAry(intAry []int, i int) bool {
	for _, v := range intAry {
		if v == i {
			return true
		}
	}
	return false
}
0