結果
| 問題 |
No.197 手品
|
| コンテスト | |
| ユーザー |
gogotea
|
| 提出日時 | 2015-04-29 00:33:02 |
| 言語 | Go1.4 (1.4.2) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,755 bytes |
| コンパイル時間 | 1,552 ms |
| コンパイル使用メモリ | 32,640 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 03:35:59 |
| 合計ジャッジ時間 | 2,946 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 43 |
ソースコード
package main
import (
"bufio"
"fmt"
"io"
"os"
"strconv"
)
func main() {
sc := NewScanner(os.Stdin)
before, _ := sc.NextLine()
N, _ := sc.NextInt()
after, _ := sc.NextLine()
fmt.Println(solve(before, after, N))
}
func solve(before, after string, n int) string {
const success = "SUCCESS"
const failure = "FAILURE"
tab := [8][3]int{
{0, 0, 0},
{1, 2, 4},
{1, 4, 2},
{3, 5, 6},
{4, 2, 1},
{3, 6, 5},
{5, 6, 3},
{7, 7, 7},
}
nb := toInt(before)
na := toInt(after)
if n == 0 {
if nb == na {
return failure
} else {
return success
}
} else if n == 1 {
if tab[nb][0] == na || tab[nb][1] == na {
return failure
} else {
return success
}
} else {
if tab[nb][0] == na || tab[nb][1] == na || tab[nb][2] == na {
return failure
} else {
return success
}
}
}
func toInt(s string) int {
n := 0
if s[0] == 'o' {
n += 4
}
if s[1] == 'o' {
n += 2
}
if s[2] == 'o' {
n += 1
}
return n
}
type Scanner struct {
*bufio.Scanner
}
func NewScanner(r io.Reader) *Scanner {
return &Scanner{
bufio.NewScanner(r),
}
}
func (s *Scanner) Next() (string, error) {
s.Scanner.Split(bufio.ScanWords)
return s.nextToken()
}
func (s *Scanner) NextLine() (string, error) {
s.Scanner.Split(bufio.ScanLines)
return s.nextToken()
}
func (s *Scanner) nextToken() (string, error) {
sc := s.Scanner
if sc.Scan() {
return sc.Text(), nil
}
if sc.Err() != nil {
return "", sc.Err()
}
return "", io.EOF
}
func (s *Scanner) NextInt() (int, error) {
token, err := s.Next()
if err != nil {
return 0, err
}
return strconv.Atoi(token)
}
func (s *Scanner) NextLong() (int64, error) {
token, err := s.Next()
if err != nil {
return 0, err
}
return strconv.ParseInt(token, 10, 64)
}
gogotea