Amedeo
SYMBIOSYS OF
PURPOSE & STYLE
Follow us

Search

未分類
  -  未分類

Problem Reversort Note: The main parts of the statements of the problems "Reversort" and "Reversort Engineering" are identical, except for the last paragraph. The problems can otherwise be solved independently. Reversort is an algorithm to sort a list of distinct integers in increasing order. The algorithm is based on the "Reverse" operation. Each application of this operation reverses the order of some contiguous part of

Go言語でソート ソートしたい配列(スライス)をaとする。aの要素は、すべてint型とする。 1.昇順sort.Sort(sort.IntSlice(a)) 2.降順sort.Sort(sort.Reverse(sort.IntSlice(a))) 練習問題 [B - Card Game for Two](https://atcoder.jp/contests/abc088/tasks/abc088_b) 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) } 参考 https://golang.org/pkg/sort