結果

問題 No.207 世界のなんとか
ユーザー gogoteagogotea
提出日時 2015-05-16 01:10:18
言語 Go1.4
(1.4.2)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,188 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 33,664 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-03 20:18:51
合計ジャッジ時間 962 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

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

func main() {
	sc := NewScanner(os.Stdin)
	A, _ := sc.NextInt()
	B, _ := sc.NextInt()

	for i := A; i <= B; i++ {
		if i%3 == 0 {
			fmt.Println(i)
		} else if includedThree(i) {
			fmt.Println(i)
		}
	}
}

// BenchmarkIncludedThree  20000000  119 ns/op  0 B/op  0 allocs/op
// BenchmarkIncludedThreeByStringsContains  5000000  245 ns/op  15 B/op  1 allocs/op
func includedThree(n int) bool {
	for n > 0 {
		if n%10 == 3 {
			return true
		}
		n /= 10
	}
	return false
}

func includedThreeByStringsContains(n int) bool {
	return strings.Contains(strconv.Itoa(n), "3")
}

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) 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)
}
0