結果
| 問題 |
No.170 スワップ文字列(Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-08-07 11:19:55 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 93 ms / 5,000 ms |
| コード長 | 651 bytes |
| コンパイル時間 | 812 ms |
| コンパイル使用メモリ | 103,296 KB |
| 実行使用メモリ | 27,136 KB |
| 最終ジャッジ日時 | 2024-12-23 00:42:35 |
| 合計ジャッジ時間 | 2,554 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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);
}
}