我的問題主題可能會關閉,但請嘗試瞭解我的查詢。 我有我使用的解決我的問題一個C#代碼:C#Console.ReadLine()在解決codechef問題時要求額外的輸入
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Chef
{
class Program
{
static void Main(string[] args)
{
int t = int.Parse(Console.ReadLine());
for (int i = 0; i < t; i++)
{
String data = Console.ReadLine();
String output = "";
if (data.Contains("C") && data.Contains("E") && data.Contains("S"))
{
if (data.LastIndexOf('C') > data.LastIndexOf('E'))
output = "no";
else if (data.LastIndexOf('E') > data.LastIndexOf('S'))
output = "no";
else
output = "yes";
}
else if (data.Contains("C") && data.Contains("E"))
{
if (data.LastIndexOf('C') > data.LastIndexOf('E'))
output = "no";
else
output = "yes";
}
else if (data.Contains("E") && data.Contains("S"))
{
if (data.LastIndexOf('E') > data.LastIndexOf('S'))
output = "no";
else
output = "yes";
}
else if (data.Contains("C") && data.Contains("S"))
{
if (data.LastIndexOf('C') > data.LastIndexOf('S'))
output = "no";
else
output = "yes";
}
else
output = "yes";
Console.WriteLine(output);
}
Console.ReadKey();
}
}
}
當我運行這個程序,並複製粘貼測試用例直接輸入,它要求一個額外的輸入。測試用例在這裏
5
CES
CS
CCC
SC
ECCC
但是當我通過輸入它運行它的行它的工作正常。
有關詳細說明我已附加運行的程序
的圖像的第一輸出顯示我已粘貼整個輸入,因爲它是和它運行,直到最後的測試用例。
第二輸出顯示我已經給了一個輸入後像我擊中進入
我不知道,如果我做了任何意義,但如果任何人都得到了相同的情況或解決它,那麼請幫助我。
如果你追蹤它,你會明白爲什麼.. – BugFinder
這裏是BugFinder的含義:在這一行放置一個斷點:'int t = int.Parse(Console.ReadLine());'。以重複該問題的方式運行該程序。使用F10鍵在調試器中逐行瀏覽。使用Visual Studio中的監視窗口檢查每個步驟中的所有變量。在某個時候,你會發現這個問題。 –
因爲您在輸入中輸入了'5',循環執行五次。所以'String data = Console.ReadLine();'行將被調用5次。那麼這意味着程序會要求您輸入5次。 –