Follow us


3月 2021
  -    -  3月

Go言語でソート ソートしたい配列(スライス)をaとする。aの要素は、すべてint型とする。 1.昇順sort.Sort(sort.IntSlice(a)) 2.降順sort.Sort(sort.Reverse(sort.IntSlice(a))) 練習問題 [B - Card Game for Two]( package main import ( "fmt" "sort" ) func main() { var n int fmt.Scan(&n) a := make([]int, n) for i := 0; i < n; i++ { fmt.Scan(&a[i]) } sort.Sort(sort.Reverse(sort.IntSlice(a))) var t, u int for i := 0; i < n; i++ { if i%2 == 1 { t += a[i] } else { u += a[i] } } fmt.Println(u - t) } 参考

Google Kickstart 2021 Round A Solutions K-Goodness String Problem Charles defines the goodness score of a string as the number of indices ii such that Si≠SN−i+1Si≠SN−i+1 where 1≤i≤N/21≤i≤N/2 (11-indexed). For example, the string CABABC has a goodness score of 22 since S2≠S5S2≠S5 and S3≠S4S3≠S4. Charles gave Ada a string SS of length NN, consisting of uppercase letters and asked her to convert it into a string with a goodness score of KK. In one operation, Ada can change any character in the string to