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<stringstring>();

        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");
        }

      
    }
}


Input (stdin)
Download
  • 3
  • sam 99912222
  • tom 11122222
  • harry 12299933
  • sam
  • edward
  • harry
Your Output (stdout)
  • sam=99912222
  • Not found
  • harry=12299933
Expected Output
Download
  • sam=99912222
  • Not found
  • harry=12299933

留言

這個網誌中的熱門文章

香港袐密行動

要老是忘記, 我更記不起