Example of Dictionary ans string Split
using System;
using System.Collections.Generic;
using System.IO;
class Solution {
static void Main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
int count = int.Parse( Console.ReadLine());
var phoneBook = new Dictionary<string, string>();
for (var i=0; i < count; i++){
var b = Console.ReadLine();
//Single quote not Double
string[] words = b.Split(' ');
var name = words[0];
var tel = words[1];
phoneBook.Add(name,tel);
}
for (var i=0; i <count; i++){
var name = Console.ReadLine();
if (phoneBook.ContainsKey(name))
Console.WriteLine(name+"="+phoneBook[name]);
else
Console.WriteLine("Not found");
}
}
}
留言
張貼留言