結果

問題 No.69 文字を自由に並び替え
ユーザー yo-kondoyo-kondo
提出日時 2018-03-10 21:33:52
言語 Go
(1.22.1)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 928 bytes
コンパイル時間 12,173 ms
コンパイル使用メモリ 206,628 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-21 00:00:03
合計ジャッジ時間 12,965 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"sort"
)

// エントリポイント
func main() {
	in := bufio.NewScanner(os.Stdin)
	// 文字列A
	in.Scan()
	input1 := in.Text()
	// 文字列B
	in.Scan()
	input2 := in.Text()

	fmt.Println(stringSort(input1, input2))
}

// 文字列を並べ替えたら一致するかどうかを判定する。
// 一致する場合は、"YES"。一致しない場合は"NO"。
func stringSort(strA string, strB string) string {
	if strA == strB {
		return "YES"
	}

	aAry := make([]string, 0)
	bAry := make([]string, 0)
	for _, ch := range strA {
		aAry = append(aAry, string(ch))
	}
	for _, ch := range strB {
		bAry = append(bAry, string(ch))
	}

	// 文字ごとにsortして一致していればOK
	sort.Sort(sort.StringSlice(aAry))
	sort.Sort(sort.StringSlice(bAry))

	// 配列(スライス)の比較
	if reflect.DeepEqual(aAry, bAry) {
		return "YES"
	}
	return "NO"
}
0