Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

DadiEinarsson avatar DadiEinarsson 21 Точки

[Programming Fundamentals] Lists more exercises / Distinct list - only getting 20/100

I am having a problem with the first task in "Lists more exercises". In it the program is to delete all repeating values while keeping the first instance of the number in the list. All of my tests come back with everything working fine and the zero tests are fine in judge but the score I get is just 20/100. My code is in the link below. Could someone take a look and see where my mistake is or at least point me in the right direction?

Thanks in advance.

https://pastebin.com/ZuMUa7du

Тагове:
0
Programming Fundamentals 29/06/2017 20:41:47
melik avatar melik 285 Точки
Best Answer

Hello, DadiEinarsson.

While I was checking your code I've come to the conclusion that you're using unnecessary for loops. Basically, the solution of this problem is 2 lines of code, you need one list in order to read the input and second list in order to add the final result in it. Then, we can create foreach loop and distinct the numbers. For example: foreach (var distinctedNumbers in numbers.Distinct() and then we should add the result in our empty list which we have created earlier.

The solution should look like this - https://github.com/melikpehlivanov/Programming-Fundamentals-CSharp/blob/master/More%20Exercises%20-%20Lists/1.%20Distinct%20List/Program.cs.

I hope this will help you to understand where you're mistaking in the code and if it didn't help you please let me know and I will explain it once again!

Kind regards,

Melik.

1
27/06/2017 20:10:17
DadiEinarsson avatar DadiEinarsson 21 Точки

Thanks melik, I had totally overlooked the Distinct method.

0
kolioi avatar kolioi 641 Точки

You don't even need the foreach() loop, just write

var numbers = Console.ReadLine().Split().Select(int.Parse).Distinct();
Console.WriteLine(string.Join(" ", numbers));

and it works like a charm smiley

0
28/06/2017 11:33:45
stoyanov7 avatar stoyanov7 70 Точки

Hi, DadiEinarsson.

If you do not want to use loops, you can just make one line LINQ like this -> http://bit.ly/2tjG8Pc

0
28/06/2017 10:47:02
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.