請幫我理解, 我目前正在參加30天的代碼。我在第8天是關於C#字典的。我去運行我的代碼,但hackerrank顯示一個致命的錯誤。但是,當我在Visual Studio中運行我的代碼時,它一切正常。這是我的代碼。謝謝Hackerrank/30天的代碼/天8
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 N, phoneNum;
string name;
N = Convert.ToInt32(Console.ReadLine());
Dictionary<string, int> phoneBook = new Dictionary<string, int>();
for(int index = 0; index < N; ++index)
{
name = Console.ReadLine();
phoneNum = Convert.ToInt32(Console.ReadLine());
phoneBook.Add(name, phoneNum);
}
for(int index = 0; index < N; ++index)
{
name = Console.ReadLine();
if(phoneBook.ContainsKey(name) == true)
Console.WriteLine("{0}={1}",name, phoneBook[name]);
else
Console.WriteLine("Not found");
}
}
}
錯誤:
Unhandled Exception: System.FormatException: Input string was not in a correct format. at System.Number.StringToNumber (System.String str, NumberStyles options, System.NumberBuffer& number
您確定它期待C#代碼。您的代碼中有評論說:「從STDIN ... STDOUT讀取輸入」。聽起來像C++。 – Jay
所以我們應該猜測「致命錯誤」是什麼? – mason
你得到了什麼錯誤 –