0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

オフラインどう書く14回参考問題をGo言語で解いてみた

Last updated at Posted at 2013-09-21

面白そうだったしだれも書いてなかったから書いてみたけど、何だかものすごくつまらないアルゴリズムになってしまった。

解くのにかかった時間は一時間ぐらい。解法はすぐ出たんだけどGo言語でどうやって点を四つ選ぶかで少し悩んだ。

問題:http://nabetani.sakura.ne.jp/hena/ord14crosscircle/

crossing.go
package main

import (
	"fmt"
)

func test(n int, input string, except int) {
	actual := 0
	
	//四重ループっておい
	for i1, c1 := range input {
		for i2, c2 := range input[i1+1:] {
			for i3, c3 := range input[i1+i2+2:] {
				for _, c4 := range input[i1+i2+i3+3:] {
					//向かいの点がそれぞれ同じなら交差してる
					if c1 == c3 && c2 == c4  {
						actual += 1
					}
				}
			}
		}
	}
	
	fmt.Printf("%d : %d == %d => %t\n", n, except, actual, except == actual)
}

func main() {
	test(0, "aabbca1bcb", 14);
	test(1, "111ZZZ", 0);
	test(2, "v", 0);
	//以下省略...
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?