3
3

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.

[POH7]Goで彼女を作る

Posted at

業務でGoを使い始めたものの、もっとGoで書きたいなーという時に
https://paiza.jp/poh/ando
が始まってたので、(個人的に)流行りのGoで挑戦してみた所存です

http://paiza.hatenablog.com/entry/2016/01/21/【結果発表】プログラミングで彼女ができた人続
を見て今更ですが自分のコードを晒す気になったので書きます

眼帯と水着以外は解けているので、残りは気が向いた時にでも・・・

つり目セット

go
package main
import "fmt"
func main(){
    var a int
    fmt.Scan(&a)
    result := ""
    for{
        result += "Ann"
        a = a-1
        if a == 0 {
            break
        }
    }
    fmt.Println(result)
}

カーディガンセット

go
package main
import "fmt"
func main(){
    // 自分の得意な言語で
    // Let's チャレンジ!!
    var input int
    fmt.Scan(&input)
    fmt.Println(Fact(input))
}

func Fact(num int) int {
    if num == 1{
        return 1
    }
    return num * Fact(num -1)
}

セーラー服セット

go
package main
import "fmt"
func main(){
    var count int
    var line string
    result := ""
    fmt.Scan(&count)
    for{
        count--
        fmt.Scan(&line)
        result += line
        if(count == 0){
            break
        }
        result += "_"
    }
    fmt.Println(result)
}

ポニーテールセット

go
package main
import "fmt"
func main(){
    var count int
    fmt.Scan(&count)
    result := ""
    for {
        result += fmt.Sprint(count) +"\n"
        count--
        if count == 0 {
            break
        }
    }
    result  += "0!!"
    fmt.Println(result)
}

ロングヘアセット

go
package main
import "fmt"
func main(){   
    var line string
    result := 0
    for i:=0; i<5; i++ {
        fmt.Scan(&line)
        if line == "yes" {
            result++
        }else{
            result--
        }
    }
    if result > 0 {
        fmt.Println("yes")
    }else{
        fmt.Println("no")
    }
}

ショートヘアセット

go
package main
import "fmt"
func main(){
    input, result := 0, 0
    fmt.Scan(&input)
    result += input
    fmt.Scan(&input)
    result += input    
    fmt.Println(fmt.Sprint(result))
}

ツインテールセット

go
package main
import "fmt"
func main(){
    // 自分の得意な言語で
    // Let's チャレンジ!!
    var cp1, cp2 float32
    cp1 = getCp()
    cp2 = getCp()
    if cp1 > cp2 {
        fmt.Println(1)
    }else{
        fmt.Println(2)
    }
}

func getCp() float32 {
    var coffein, price int
    fmt.Scan(&coffein)
    fmt.Scan(&price)
    return (float32)(coffein) /(float32)(price)
}

めがね

go
package main
import "fmt"

func main(){
    var aryNum1, aryNum2 int
    fmt.Scan(&aryNum1)
    pict1 := makePict(aryNum1)
    fmt.Scan(&aryNum2)
    pict2 := makePict(aryNum2)
    pos := matchPict(pict1, aryNum1, pict2, aryNum2)
    fmt.Println(fmt.Sprint(pos[0]), fmt.Sprint(pos[1]))
}

func matchPict(pict1 [][]int, size1 int, pict2 [][]int, size2 int) []int {
    result := []int {0, 0}
    checkLen  := size1 -size2
    isMatch    := false
    for h1:=0; h1<=checkLen && !isMatch; h1++ {
        for w1:=0; w1<=checkLen && !isMatch; w1++{
            if pict2[0][0] != pict1[h1][w1] {
                continue
            }
            isMatch    := true
            for h2:=0; h2<size2 && isMatch; h2++{
                for w2:=0; w2<size2 && isMatch; w2++ {
                    if pict2[h2][w2] != pict1[h1 +h2][w1 +w2] {
                        isMatch = false
                        break
                    }
                }
            }
            if isMatch {
                result[0] = h1
                result[1] = w1
                break
            }
        }
    }
    return result
}

func makePict(len int) [][]int {
    var dot int
    var pict = make([][]int, len, len)
    for i:=0; i<len; i++{
        pict[i] = make([]int, len)
        for m:=0; m<len; m++{
            fmt.Scan(&dot)
            pict[i][m] = dot
        }
    }
    return pict
}

サンタ服

go
package main
import "fmt"
import "sort"

func main(){
    x, y, z, count := ScanCakeInfo()
    xPoint := []int{0, x}
    yPoint := []int{0, y}    
    ScanCutInfo(&xPoint, &yPoint, count)
    xw := CalcWidthMin(&xPoint, x)
    yw := CalcWidthMin(&yPoint, y)
    fmt.Println(fmt.Sprint(xw *yw *z))
}

func CalcWidthMin(pointTable *[]int, maxWidth int) int {
    result := maxWidth
    var width int
    for i:=0; i<len(*pointTable) -1; i++ {
        width = (*pointTable)[i +1] -(*pointTable)[i]
        if width < result {
            result = width
        }
    }
    return result
}

func ScanCutInfo(xTable, yTable *[]int, count int) {
    var data []int
    for i:=0; i<count; i++ {
        data = GetData()
        if data[0] == 0 {
            *xTable = append(*xTable, data[1])
        }else{
            *yTable = append(*yTable, data[1])
        }
    }
    if !sort.IntsAreSorted(*xTable) {
        sort.Ints(*xTable)
    }
    if !sort.IntsAreSorted(*yTable) {
        sort.Ints(*yTable)
    }
}

func ScanCakeInfo() (int, int, int, int) {
    var x, y, z, count int
    fmt.Scan(&x)
    fmt.Scan(&y)
    fmt.Scan(&z)
    fmt.Scan(&count)
    return x, y, z, count
}

func GetData() []int {
    var result = make([]int, 2)
    fmt.Scan(&result[0])
    fmt.Scan(&result[1])
    return result
}

縞ニーソセット

go
package main
import "fmt"
func main(){
    
    var interval, total int
    fmt.Scan(&interval)
    fmt.Scan(&total)
    result := ""
    for looper:=0; looper<total; looper++ {
        if (looper/interval) & 0x1 == 0 {
            result += "R"
        }else{
            result += "W"
        }
    }
    
    fmt.Println(result)
}

golang楽しいですね
ただcみたいになってる気がするし、この書き方が良いのかちょっとわからない...
go的な作法とか面白いやり方とかあるんですかね

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?