結果
| 問題 |
No.517 壊れたアクセサリー
|
| コンテスト | |
| ユーザー |
bluemegane
|
| 提出日時 | 2018-09-13 11:46:49 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 34 ms / 2,000 ms |
| コード長 | 1,242 bytes |
| コンパイル時間 | 870 ms |
| コンパイル使用メモリ | 114,404 KB |
| 実行使用メモリ | 28,300 KB |
| 最終ジャッジ日時 | 2024-07-01 04:22:00 |
| 合計ジャッジ時間 | 2,183 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System.Linq;
using System.Collections.Generic;
using System;
public class Hello
{
public static void Main()
{
var d = new Dictionary<char, char>();
var n = int.Parse(Console.ReadLine().Trim());
setDic(d, n);
n = int.Parse(Console.ReadLine().Trim());
setDic(d, n);
var res = getAns(d);
Console.WriteLine(res);
}
public static string getAns (Dictionary<char,char> d)
{
var c = d.Count(x => x.Value == '?');
if (c >= 2) return "-1";
var hs = new HashSet<char>();
foreach (var x in d) hs.Add(x.Key);
foreach (var x in d)
hs.Remove(x.Value);
var nextchar = hs.First();
var res = nextchar.ToString();
while (d[nextchar]!= '?')
{
res += d[nextchar];
nextchar = d[nextchar];
}
return res;
}
public static void setDic (Dictionary<char,char> d,int n)
{
for (int i = 0; i < n; i++)
{
var s = Console.ReadLine().Trim();
var sL = s.Length;
for (int j = 0; j < s.Length - 1; j++) d[s[j]] = s[j + 1];
if (!d.ContainsKey(s[sL - 1])) d[s[sL - 1]] = '?';
}
}
}
bluemegane