1.iを入力して辞書に保存し、再度入力を取得して、辞書に含まれているかどうかを確認する必要があります。
2.これを試しましたが、エラーが発生しました(入力文字列が正しい形式ではありません)。
3.コンパイル時にエラーを出すことはありませんが、実行時にエラーが発生しています。これに関する問題があります。
4.私の入力は以下のとおりです。 - SAM 99912222
トム11122222
ハリー12299933
SAM
エドワード
ハリー・リードの代わりに
5.()。 ReadLine()も試みましたが、問題は同じです。C#コードでランタイムエラーが発生する
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution
{
static void Main()
{
int n = Convert.ToInt32(Console.Read());
Dictionary<string, int> phbook = new Dictionary<string, int>();
for (int i = 0; i < n; i++)
{
string name = Console.Read().ToString();
int phonno = Convert.ToInt32(Console.ReadLine());
phbook.Add(name, phonno);
}
foreach (var keypairs in phbook)
{
string namet = Console.Read().ToString();
if (phbook.ContainsKey(namet))
{
Console.Write("{0}={1}", namet, phbook[namet]);
}
else
{
Console.Write("Not found");
}
}
}
}
完全なエラーが
Unhandled Exception:
System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x00057] in <a07d6bf484a54da2861691df910339b1>:0
at System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00015] in <a07d6bf484a54da2861691df910339b1>:0
at System.Int32.Parse (System.String s, System.IFormatProvider provider) [0x00008] in <a07d6bf484a54da2861691df910339b1>:0
at System.Convert.ToInt32 (System.String value) [0x0000b] in <a07d6bf484a54da2861691df910339b1>:0
at Solution.Main() [0x00034] in solution.cs:15
[ERROR] FATAL UNHANDLED EXCEPTION: System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x00057] in <a07d6bf484a54da2861691df910339b1>:0
at System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00015] in <a07d6bf484a54da2861691df910339b1>:0
at System.Int32.Parse (System.String s, System.IFormatProvider provider) [0x00008] in <a07d6bf484a54da2861691df910339b1>:0
at System.Convert.ToInt32 (System.String value) [0x0000b] in <a07d6bf484a54da2861691df910339b1>:0
at Solution.Main() [0x00034] in solution.cs:15
あなたの入力は何ですか? –
'Console.ReadLine()によって入力されたものがintに変換できない可能性があります –
@HiranPerera入力で質問を再編集しました。 – shindvii