結果

問題 No.170 スワップ文字列(Easy)
ユーザー hogekihogeki
提出日時 2016-08-07 11:19:55
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 118 ms / 5,000 ms
コード長 651 bytes
コンパイル時間 2,248 ms
コンパイル使用メモリ 99,856 KB
実行使用メモリ 33,952 KB
最終ジャッジ日時 2023-08-24 16:33:07
合計ジャッジ時間 4,892 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
24,240 KB
testcase_01 AC 117 ms
32,048 KB
testcase_02 AC 55 ms
20,400 KB
testcase_03 AC 57 ms
22,316 KB
testcase_04 AC 57 ms
22,224 KB
testcase_05 AC 118 ms
33,952 KB
testcase_06 AC 116 ms
30,096 KB
testcase_07 AC 57 ms
22,136 KB
testcase_08 AC 56 ms
22,284 KB
testcase_09 AC 56 ms
22,212 KB
testcase_10 AC 87 ms
30,276 KB
testcase_11 AC 55 ms
22,256 KB
testcase_12 AC 56 ms
22,356 KB
testcase_13 AC 56 ms
22,332 KB
testcase_14 AC 56 ms
22,228 KB
testcase_15 AC 57 ms
22,392 KB
testcase_16 AC 57 ms
24,344 KB
testcase_17 AC 55 ms
20,352 KB
testcase_18 AC 56 ms
22,440 KB
testcase_19 AC 55 ms
22,212 KB
testcase_20 AC 59 ms
22,200 KB
testcase_21 AC 55 ms
22,328 KB
testcase_22 AC 56 ms
22,328 KB
testcase_23 AC 57 ms
22,320 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;

class SwapString
{
	static void Main(String[] args)
	{
		String S = Console.ReadLine();
		Queue<String> countQueue = new Queue<String>();
		HashSet<String> countHash = new HashSet<String>();

		countQueue.Enqueue(S);
		countHash.Add(S);
		while(countQueue.Count > 0)
		{
			String s = countQueue.Dequeue();
			for(int i=0; i < s.Length-1; i++)
			{
				char[] arr = s.ToCharArray();
				char temp = arr[i+1];
				arr[i+1] = arr[i];
				arr[i] = temp;
				String t = new String(arr);
				if(countHash.Add(t))
				{
					countQueue.Enqueue(t);
				}
			}
		}
		Console.WriteLine(countHash.Count-1);
	}
}
0