Професионална програма
Loading...
Stefan9241 avatar Stefan9241 2 Точки

C# Advanced Exam - 20 February 2021

Здравейте,от 2 дена решавам теста и на 1 и 2ра задача стигам до 40/100. Примерните inputs  са ми верни и не мога да си намеря грешката,направо се побърках :D..Моля,който ги е решил да покаже как.

Линк към judge: https://judge.softuni.bg/Contests/Practice/Index/2813#0
Моето решение на 01.Gondor - https://pastebin.com/rjLGgwZW

The Fight for Gondor
Sauron’s army is marching towards Gondor. Vicious waves of orcs are getting ready to attack Aragorn’s people and make their way into the city.
First, you will be given a number equal to the waves of orcs. On the second line you will be given the plates of the Aragorn's defense. Then, on each next line (for each wave), you receive the power of each orc  warrior. Additionally, on every third wave, the people build a new plate (extra line with a single integer) before the Sauron's warriors attack. In order to enter the city, the orcs have to destroy all the plates.
Until there are no more plates or orcs, the last orc warrior attacks the first plate:
If the warrior's value is greater, he destroys the plate and lowers his value by the plate's value, then attacks the next plate, until his value reaches 0.
If the plate's value is greater, the warrior dies and the plate decreases its value by the warrior's value.
If their values are equal, the warrior dies and the plate is destroyed.
Input
First line: integer- the number of waves
Second line: integers, representing the plates, separated by a single space.
For each wave: integers, representing the warrior orcs, separated by a single space.
On every third wave, you will be given an extra line with a single integer, which will be the plate you need to add. [!] Add the plate before processing the attacks. [!]
Output
On the first line of output – print if the orcs destroyed the Gondor's defense:
True: "The orcs successfully destroyed the Gondor's defense."
False: "The people successfully repulsed the orc's attack."
On the second line - print all plates or orcs left, separated by comma and a white space:
If there are warriors: "Orcs left: {orc1}, {orc2}, {orc3}, …"
If there are plates: "Plates left: {plate1}, {plate2}, {plate3}, …"
Constraints
All of the given numbers will be valid integers in the range [1, 100].
Not all waves may be needed to destroy the defense.
There will always be a winning side, meaning either no orcs or plates left.
Examples
Input    Output    Comment
3
10 20 30
4 5 1
10 5 5
10 10 10
4    The people successfully repulsed the orc's attack.
Plates left: 4    First wave (4 5 1):
Orc (1) attacks Plate (10) => dies and plate is now 9.
Orc (5) attacks Plate (9) => dies and plate is now 4.
Orc (4) attacks Plater (4) => dies and plate is gone.
Second wave (10 5 5):
Orc (5) attacks Plate (20) => dies and plate is now 15.
Orc (5) attacks Plate (15) => dies and plate is now 10.
Orc (10) attacks Plate (10) => dies and plate is gone.
Third wave (10 10 10):
People build a new plate (4), plates are now: 30 4
Orc (10) attacks Plate (30) => dies and plate is now 20.
Orc (10) attacks Plate (20) => dies and plate is now 10.
Orc (10) attacks Plate (10) => dies and plate is gone.
We have no more waves and one plate left (4) => see the output.
5
10 30 10
3 3 4
10 10 10
5 5
5
7 6
8 6 7    The orcs successfully destroyed the Gondor's defense.
Orcs left: 1, 7    First wave (3 3 4):
Orc (4) attacks Plate (10) => dies and plate is now 6.
Orc (3) attacks Plate (6) => dies and plate is now 3.
Orc (3) attacks Plater (3) => dies and plate is gone.
Second wave (10 10 10):
Orc (10) attacks Plate (30) => dies and plate is now 20.
Orc (10) attacks Plate (20) => dies and plate is now 10.
Orc (10) attacks Plate (10) => dies and plate is gone.
Third wave (5 5):
People build a new plate (5), plates are now: 10 5
Orc (5) attacks Plate (10) => dies and plate is now 5.
Orc (5) attacks Plate (5) => dies and plate is gone.
Fourth wave (7 6):
Orc (6) attacks Plate (5) => the orc is now 1 and the plate is gone.
We have no more plates, so the waves stop coming => see the output. Also, we stop the input. (8 6 7 is not proceeded, but is in the input because the waves are 5)


 

Моето решение на 02.Warships - https://pastebin.com/MVcnsZLh

2. Warships
You have been tasked with the development of an online version of the famous Warships game. You start by developing a console version.
We get as input the size of the field in which our Warships are situated. The field is always a square. After that we will receive the coordinates for the attacks for each player in pairs of integers (row, column). If there is an attack on invalid coordinates - ignore the attack. The possible characters that may appear on the screen are:
* – a regular position on the field
< – ship of the first player.
> – ship of the second player
# – a sea mine that explodes when attacked
Each time when an attack hits a ship or a mine replace it with 'X'. Keep track of the count of ships remaining for each player. If a player hits a mine it explodes destroying all ships in adjacent fields (friend or foe). If a player destroys all enemy ships, the program stops and you have to print the following message: "Player {One/Two} has won the game! {totalCountShipsDestroyed} ships have been sunk in the battle."
If the list of attack commands ends before any of the player has won, you have to print the following message:     
"It's a draw! Player One has {countOfShips} left. Player Two has {countOfShips} left."
Input
Field size – an integer number.
Attack commands – All attack coordinates will be received on a single line. There will be a coma (,) between each set of coordinates and a whitespace (" ") between every two integers representing the row and column to attack.
The field: some of the following characters (*, <, >, #), separated by whitespace (" ");
Output
There are three types of output:
If player One wins, print the following output: "Player One has won the game! {totalCountShipsDestroyed} ships have been sunk in the battle."
If player Two wins, print the following output: "Player Two has won the game! {totalCountShipsDestroyed} ships have been sunk in the battle."
If there are no more commands and none of the above cases had happened, you have to print the following message: "It's a draw! Player One has {countOfShips} ships left. Player Two has {countOfShips} ships left."
Constraints
The field size will be a 32-bit integer in the range [4 … 2 147 483 647].
Player One always starts first.
A player will never attack the coordinates of one of his own ships. 
There will be no incomplete sets of attack coordinates – e.g. – "0 1,2 3,2".
There will never be 2 mines in adjacent fields.
There will not be a test where both players lose their last ships in the same turn.
Examples
Input    Output    Comment
5
0 0,-1 -1,2 2,4 4,4 2,3 3,3 6
# < * < *
> > * < *
* * > * *
< * * * *
* * > * *    Player One has won the game! 5 ships have been sunk in the battle.
    Player One attacks first at coordinates 0,0 and hits a mine. All adjacent fields (including diagonally) are blasted. The enemy ships at 1,0 and 1,1 are destroyed as well as the friendly ship at 0,1. The field now looks like this:
# X * < *
X X * < *
* * > * *
< * * * *
* * > * *
Player Two attacks on invalid coordinates so we ignore it.
Player One attacks 2,2 and destroys an enemy ship.
Player Two attacks 4,4 and misses. 
Player One attacks 4,2 and destroys the last enemy ship. The game is over so we ignore any remaining attack coordinates and print message. The final state of the map is the following:
X X * < *
X X * < *
* * X * *
< * * * *
* * X * *
6
0 0,1 0,5 5
* * * * * *
< * * * < *
* * > > * *
* * * * * *
* * * * * *
* * * * * *    It’s a draw! Player One has 1 ships left. Player Two has 2 ships left.    
5
1 1,0 3,2 1,1 3,4 1,3 0
# * * < *
* * * < *
* * > * *
< * * > *
* * > * *    Player Two has won the game! 3 ships have been sunk in the battle.    

Благодаря!

Тагове:
0
C# Advanced 27/07/2021 16:13:03
svephoto avatar svephoto 981 Точки

Здравей, Stefan9241,

 

Има нужда да дадеш и условията на двете задачи (направо тук в твоя пост), такава е практиката при задаване на въпрос за решение на дадена задача, освен това ресурсите/файловете им може да не са достъпни за всички. Трябва да дадеш също и линкове с твоите решения към момента, за да може да ти се даде адекватна помощ и отговор на въпросите ти.

0
27/07/2021 11:21:23
Stefan9241 avatar Stefan9241 2 Точки

Благодаря, редактирах го.

1
svephoto avatar svephoto 981 Точки

Предложение за работещо със 100/100 решение на първата задача: https://pastebin.com/DNcJV9tb.

1
28/07/2021 07:36:23
Stefan9241 avatar Stefan9241 2 Точки

Благодаря !

0
svephoto avatar svephoto 981 Точки

Моля. yes

0