0
I'm having problems with SoloLearn's Compiler... Any help?
I ran the code below for the New drivers license Coach problem: string name = Console.ReadLine(); int number = Convert.ToInt32(Console.ReadLine()); string[] people = new string[5]; people[0] = name; for(int i = 1; i < 5; i++){ people[i] = Console.ReadLine(); } Array.Sort(people); int nameIndex = Array.IndexOf(people , name); int minutes = (nameIndex + 1)/ number * 20; Console.Write(minutes); With the inputs, Aaron, 1, Jane, Max, Olivia, Sam... It returns 80 instead of 20, I tried the same code on Vs and I got 20
6 Respuestas
+ 1
Here problem contains 3 lines of input..
Ex:
Aron
1
Jan Max Olivia Sam
By your code 3rd line entirely goes to people[1], next 2 to 4 stores empty string...
So while sorting empty string comes first 0,1,2 positions of array. So nameIndex = 3
So you get 80. Hence
Read the third line into a string and split into array values.. Then you get the correct result.
+ 1
Nwogu Kene
I think you replied something before this but I forgot to reply.. If not ingore this..
The input will be provided to this is in the form as I given example above.. You should write Program according to that..
And
You're Wel come....
+ 1
Oh.. Why to give up?
In c# also, you can apply just a split statement like this..
string name = Console.ReadLine();
int number = Convert.ToInt32(Console.ReadLine());
String s=Console.ReadLine();
s = s+" "+name ;
string[] people = s.Split();
Array.Sort(people);
0
Thank you...
0
Yes, you are very much right. I corrected it with python because I don't like manipulating arrays/lists with C# and it worked. Thanks again.
0
Oh... Thanks a lot!