C# 根据数字拆分后,我如何取名字和姓氏?
我想根据时间取名字和姓氏C# 根据数字拆分后,我如何取名字和姓氏?,c#,C#,我想根据时间取名字和姓氏 int input = Convert.ToInt32(Console.ReadLine()); for (int i = 0; i < input; i++) { int numberOfFrnd = Convert.ToInt32(Console.ReadLine()); for (int j = 0; j < numberOfFrnd; j++) { var anotherInput = Console.ReadLine();
int input = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < input; i++)
{
int numberOfFrnd = Convert.ToInt32(Console.ReadLine());
for (int j = 0; j < numberOfFrnd; j++)
{
var anotherInput = Console.ReadLine();
var splitInput = anotherInput.Split(' ');
var Fn = Convert.ToString(splitInput[0]);
var time = Convert.ToInt32(splitInput[1]);
}
}
这里有一种可能是使用一个用lambda表达式排序的
列表
:
static void Main(string[] args)
{
List<Tuple<string, int>> PeopleStuckInThePond = new List<Tuple<string, int>>();
Console.Write("Number of Test Cases? ");
int input = Convert.ToInt32(Console.ReadLine());
for(int i = 0; i <input; i++)
{
PeopleStuckInThePond.Clear();
Console.WriteLine("Case " + (i + 1).ToString() + " of " + input.ToString());
Console.Write("Number of Friends? ");
int numberOfFrnd = Convert.ToInt32(Console.ReadLine());
for (int j = 0; j < numberOfFrnd; j++)
{
Console.Write("Friend " + (j + 1).ToString() + " of " + numberOfFrnd.ToString() + ": ");
var anotherInput = Console.ReadLine();
var splitInput = anotherInput.Split(' ');
var Fn = Convert.ToString(splitInput[0]);
var time = Convert.ToInt32(splitInput[1]);
PeopleStuckInThePond.Add(new Tuple<string, int>(Fn, time));
}
PeopleStuckInThePond.Sort((a, b) => b.Item2.CompareTo(a.Item2));
Console.WriteLine("Answer: " + PeopleStuckInThePond.First().Item1 + " " + PeopleStuckInThePond.Last().Item1);
Console.WriteLine("");
}
Console.Write("Press Enter to Quit");
Console.ReadLine();
}
基于时间?几点?这个问题对我来说毫无意义。我不知道你的输入是如何转化为输出的。也许这是属于你的时间意味着第二部分21191512@LarsTech我的猜测(基于我高超的纵横字谜和数独技能)是用户输入1和5,返回最小值名称(9)和最大值名称(20),但这是一个完整的猜测@戴维格:这是个不错的解释。我无法通过索引值顺序。使用“时间”作为描述也没有帮助。
static void Main(string[] args)
{
List<Tuple<string, int>> PeopleStuckInThePond = new List<Tuple<string, int>>();
Console.Write("Number of Test Cases? ");
int input = Convert.ToInt32(Console.ReadLine());
for(int i = 0; i <input; i++)
{
PeopleStuckInThePond.Clear();
Console.WriteLine("Case " + (i + 1).ToString() + " of " + input.ToString());
Console.Write("Number of Friends? ");
int numberOfFrnd = Convert.ToInt32(Console.ReadLine());
for (int j = 0; j < numberOfFrnd; j++)
{
Console.Write("Friend " + (j + 1).ToString() + " of " + numberOfFrnd.ToString() + ": ");
var anotherInput = Console.ReadLine();
var splitInput = anotherInput.Split(' ');
var Fn = Convert.ToString(splitInput[0]);
var time = Convert.ToInt32(splitInput[1]);
PeopleStuckInThePond.Add(new Tuple<string, int>(Fn, time));
}
PeopleStuckInThePond.Sort((a, b) => b.Item2.CompareTo(a.Item2));
Console.WriteLine("Answer: " + PeopleStuckInThePond.First().Item1 + " " + PeopleStuckInThePond.Last().Item1);
Console.WriteLine("");
}
Console.Write("Press Enter to Quit");
Console.ReadLine();
}
Number of Test Cases? 2
Case 1 of 2
Number of Friends? 5
Friend 1 of 5: Ayan 20
Friend 2 of 5: Punom 11
Friend 3 of 5: Eifty 9
Friend 4 of 5: Prioti 15
Friend 5 of 5: Surovi 12
Answer: Ayan Eifty
Case 2 of 2
Number of Friends? 3
Friend 1 of 3: FirstVictim 61
Friend 2 of 3: ThirdViction 32
Friend 3 of 3: SecondViction 45
Answer: FirstVictim ThirdViction
Press Enter to Quit