結果
| 問題 |
No.170 スワップ文字列(Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-03-29 02:00:09 |
| 言語 | Go (1.23.4) |
| 結果 |
AC
|
| 実行時間 | 17 ms / 5,000 ms |
| コード長 | 1,469 bytes |
| コンパイル時間 | 11,771 ms |
| コンパイル使用メモリ | 220,384 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-23 00:21:05 |
| 合計ジャッジ時間 | 12,701 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
package main
import (
"bufio"
"os"
"strconv"
"fmt"
"sort"
)
var s = bufio.NewScanner(os.Stdin)
func next() string {
s.Split(bufio.ScanWords)
s.Scan()
return s.Text()
}
func nextLine() string {
s.Split(bufio.ScanLines)
s.Scan()
if nil != s.Err() {
panic(s.Err())
}
return s.Text()
}
func nextInt() int {
i, e := strconv.Atoi(next())
if e != nil {
panic(e)
}
return i
}
func nextLong() int64 {
i, e := strconv.ParseInt(next(), 10, 64)
if e != nil {
panic(e)
}
return i
}
func next_permutation(a []rune) bool {
for i := len(a) - 2; i >= 0; i-- {
if a[i] < a[i+1] {
for j := len(a) - 1; j >= 0; j-- {
if a[j] > a[i] {
a[i], a[j] = a[j], a[i]
reverse(a, i+1, len(a)-(i+1))
return true
}
}
}
}
reverse(a, 0, len(a))
return false
}
func reverse(a []rune, start int, length int) {
var end = start + length - 1
for start < end {
a[start], a[end] = a[end], a[start]
start++
end--
}
}
//https://www.socketloop.com/tutorials/golang-sort-and-reverse-sort-a-slice-of-runes
type RuneSlice []rune
func (p RuneSlice) Len() int { return len(p) }
func (p RuneSlice) Less(i, j int) bool { return p[i] < p[j] }
func (p RuneSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func main() {
S := nextLine()
s := RuneSlice([]rune(S))
var m = make(map[string]int)
sort.Sort(s)
for {
str := string(s)
m[str] = 1
if !next_permutation(s) {
break
}
}
fmt.Println(len(m) - 1)
}