結果

問題 No.170 スワップ文字列(Easy)
ユーザー yuki2006yuki2006
提出日時 2015-03-29 02:00:09
言語 Go
(1.22.1)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 1,469 bytes
コンパイル時間 19,349 ms
コンパイル使用メモリ 216,208 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2023-08-24 16:12:08
合計ジャッジ時間 12,399 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 17 ms
6,548 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 17 ms
6,548 KB
testcase_06 AC 18 ms
6,540 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 7 ms
4,404 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)

}



0