[Programming Fundamentals] Lambda and Linq - Exercise - 04. SoftUni Beer Pong - Софтуерен университет

+ Нов въпрос
paskal06 avatar paskal06 2 Точки

[Programming Fundamentals] Lambda and Linq - Exercise - 04. SoftUni Beer Pong

Здравейте,

Зацепил съм напълно за това как да довърша задачата и foreach-овете ми дават грешки като се опитам да напиша нещо различно от това, което съм написал в момента. Като се опитам да сложа втори foreach вътре, не ми принтира резултатите. Може ли някой да ми покаже как да си довърша задачата?  Благодаря предварително.

-  https://pastebin.com/gLHijxiz

 

4.   SoftUni Beer Pong

In SoftUni it is time for the annual beer pong tournament. Last year the competition was a total disaster, because nobody was in “condition” to keep track of the scores. Now it is your job to write a program, which will keep track of the total results. The competition’s rules are simple:

  • All contestants are divided into teams
  • Every team should have exactly 3 participants
  • After a team has a total of 3 participants, any further attempt to add a participant should be ignored.
  • If a team has less than 3 participants – it gets disqualified and should not be printed.

Until you receive the command “stop the game” you will receive lines of input in the following format:

team|player|pointsMade

The total score of the team is the sum of the points made from every player.

Print every team, which has enough players in the following format:

{teamPosition}. {teamName}; Players:

###{firstPlayerName}: {points}

###{secondPlayerName}: {points}

###{thirdPlayerName}: {points}

Order the teams by total points in descending order and order each team’s players by the amount of points made, again in descending order.

Constraints

  • You will not receive a player’s name, which already exists in the team it’s trying to be inserted into.
  • Points will be in the interval [0…2147483647].
  • The total points of the teams and the points of the players in the same team will not be equal.

Examples

Input

Output

Jubrata|Retro|57

Pesho|Destroyers|20

Gosho|Destroyers|35

Pesho|TechModule|32

Stefan|Destroyers|12

Kaloyan|TechModule|14

Meto|TechModule|24

Hrisi|Retro|59

Maria|TechModule|19

stop the game

1. TechModule; Players:

###Pesho: 32

###Meto: 24

###Kaloyan: 14

2. Destroyers; Players:

###Gosho: 35

###Pesho: 20

###Stefan: 12

Ivan|Loosers|5

Ivo|RoYaL|100

Vladi|RoYaL|120

Pesho|Trainers|22

Stefan|NoobS|12

RoYaL|RoYaL|90

Geotgi|NoobS|24

Anna|NoobS|70

Maria|Loosers|19

Pesho|Loosers|30

stop the game

1. RoYaL; Players:

###Vladi: 120

###Ivo: 100

###RoYaL: 90

2. NoobS; Players:

###Anna: 70

###Geotgi: 24

###Stefan: 12

3. Loosers; Players:

###Pesho: 30                      

###Maria: 19

###Ivan: 5

Тагове:
0
Programming Fundamentals 17/07/2017 23:39:39
icowwww avatar icowwww 571 Точки
Best Answer

набързо добавих някои неща. В задачата е важно още като добавяш нови играчи да гледаш за броя съществуващи такива. Иначе ако просто добавиш всички пък после вземеш първите 3 добавени ще объркаш логиката на сортирането по сума точки. Затова добавих една проврерка да минава на следващи инпут ако това се случи. Вкарах втори цикъл в твоя, не знам кое те притеснява, и там изкарах играчите:

https://pastebin.com/6uCusfNv

0