Loading...

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

silvana1303 avatar silvana1303 5 Точки

Need For Speed III Programming Fundamentals Final Exam Retake 10.04.2020

Някой решил ли я е  на C# без класове и обекти? Може ли код?

code: https://pastebin.com/JfU6xcCd

 

You have just bought the latest and greatest computer game – Need for Seed III. We know that you can`t wait to start playing. Pick your favorite cars and drive them all you want!

On the first line of the standard input you will receive an integer n – the number of cars that you can obtain. On the next n lines the cars themselves will follow with their mileage and fuel available, separated by "|" in the following format:

{car}|{mileage}|{fuel}

Then, you will be receiving different commands, each on a new line, separated by " : ", until the "Stop" command is given:

  • Drive : {car} : {distance} : {fuel}
    • You need to drive the given distance and you will need the given fuel to do that. If the car doesn`t have enough fuel print:
      "Not enough fuel to make that ride"
    • If the car has the required fuel available in the tank, increase its mileage with the given distance, decrease its fuel with the given fuel and print:
      "{car} driven for {distance} kilometers. {fuel} liters of fuel consumed."
    • You like driving new cars only, so if the mileage of a car reaches 100 000 km, remove it from the collection(s). Print:
      "Time to sell the {car}!"
  • Refuel : {car} : {fuel}
    • Refill the tank of your car.
    • Each tank can hold a maximum of 75 liters of fuel, so if the given amount of fuel is more than you can fit in the tank, take only what is required to fill it up.
    • Print a message in the following format:
      "{car} refueled with {fuel} liters"
  •  
  • Revert : {car} : {kilometers}
    • Decrease the mileage of the given car with the given kilometers and print the kilometers you have decreased it with in the following format:
      "{car} mileage decreased by {amount reverted} kilometers"
    • If the mileage becomes less than 10 000km after it is decreased, just set it to 10 000km and
      DO NOT print anything.

Upon receiving the "Stop" command you need to print all cars in your possession, sorted by their mileage in decscending order, then by their name in ascending order, in the following format:
"{car} -> Mileage: {mileage} kms, Fuel in the tank: {fuel} lt."

Input/Constraints

  • The mileage and fuel of the cars will be valid, 32-bit integers and will never be negative.
  • The fuel and distance amounts in the commands will never be negative.
  • The car names in the commands will always be valid cars in your possession.

Output

  • All the output messages with the appropriate formats are described in the problem description.

Examples

Input

Output

3

Audi A6|38000|62

Mercedes CLS|11000|35

Volkswagen Passat CC|45678|5

Drive : Audi A6 : 543 : 47

Drive : Mercedes CLS : 94 : 11

Drive : Volkswagen Passat CC : 69 : 8

Refuel : Audi A6 : 50

Revert : Mercedes CLS : 500

Revert : Audi A6 : 30000

Stop

Audi A6 driven for 543 kilometers. 47 liters of fuel consumed.

Mercedes CLS driven for 94 kilometers. 11 liters of fuel consumed.

Not enough fuel to make that ride

Audi A6 refueled with 50 liters

Mercedes CLS mileage decreased by 500 kilometers

Volkswagen Passat CC -> Mileage: 45678 kms, Fuel in the tank: 5 lt.

Mercedes CLS -> Mileage: 10594 kms, Fuel in the tank: 24 lt.

Audi A6 -> Mileage: 10000 kms, Fuel in the tank: 65 lt.

Comments

After we receive the cars with their mileage and fuel, we start driving them. When we get to "Drive : Volkswagen Passat CC : 69 : 8" command, our program calculates that there is not enough fuel and we print the appropriate message. Then we refuel the Audi A6 with 50 l of fuel and Revert the Mercedes with 500 kilometers.

When we receive the "Revert : Audi A6 : 30000", we set its mileage to 10000 km, because if the current mileage of the Audi is 38543 kms and if we subtract 30000 from it, we receive 8543 kms, which is less than 10000 kms.

After all the commands, we print our current collection of cars with their current mileage and current fuel.

Input

Output

4

Lamborghini Veneno|11111|74

Bugatti Veyron|12345|67

Koenigsegg CCXR|67890|12

Aston Martin Valkryie|99900|50

Drive : Koenigsegg CCXR : 382 : 82

Drive : Aston Martin Valkryie : 99 : 23

Drive : Aston Martin Valkryie : 2 : 1

Refuel : Lamborghini Veneno : 40

Revert : Bugatti Veyron : 2000

Stop

Not enough fuel to make that ride

Aston Martin Valkryie driven for 99 kilometers. 23 liters of fuel consumed.

Aston Martin Valkryie driven for 2 kilometers. 1 liters of fuel consumed.

Time to sell the Aston Martin Valkryie!

Lamborghini Veneno refueled with 1 liters

Bugatti Veyron mileage decreased by 2000 kilometers

Koenigsegg CCXR -> Mileage: 67890 kms, Fuel in the tank: 12 lt.

Lamborghini Veneno -> Mileage: 11111 kms, Fuel in the tank: 75 lt.

Bugatti Veyron -> Mileage: 10345 kms, Fuel in the tank: 67 lt.

Тагове:
0
C# Fundamentals 25/07/2020 16:12:08
svephoto avatar svephoto 1191 Точки
Best Answer

Здравей, silvana1303,

 

Ето едно примерно решение на основата на твоя код https://pastebin.com/nCvSWbe7. Може да го разгледаш, някои неща съм добавил, други съм променил или премахнал (например break-a във вътрешния if на else-a при команда "Drive" беше излишен), направил съм и някои преструктурирания.

Обърни внимание на печатането на изхода накрая и виж в какво се различава от твоето, понеже както знаем то (печатането) също е една част от ключа към правилното решение на задачата, макар че това, което аз предлагам е само един вариант за печатане.

 

Успех!

2
26/07/2020 23:35:44
krum_43 avatar krum_43 750 Точки

Решението ти е добро.И аз следвах същата логика ,но стигнах до 20/100.

Не знам защо не се изпълнява нито една команда(в цикъла(while(true))..

Ето кода:

https://pastebin.com/7UVw6vPf

 

0
03/08/2020 17:23:38
svephoto avatar svephoto 1191 Точки

Здравей, krum_43,

 

На ред 35 имаш неправилно сплитване на командите в while цикъла и затова не ти се изпълнява нито една от тях. Твоето е (':'), а трябва да е  (" : ") - нужен ни е по един интервал от двете страни на двуеточието и освен това двойни кавички, а не единични. После на ред 37 "Drivë" има "ë" накрая - "е" с две точки отгоре вместо само "е". С тези две корекции качваме резултата на 50/100. След това на ред 50 липсва точка в края на стринга, който трябва да се отпечата. И последното е в кода за команда "Refuel" - трябва да си сметнем differentFuel преди проверката, а също и да си сетнем горивото отново преди нея. Чак след това в if-a проверяваме дали наличното гориво е по-голямо (само >, а не >=) и вътре печатаме и сетваме на 75. Липсва ти вариантът, при който горивото е <= 75 и в който печаташ същото като в if-a, но сега вече в еlse-a с тази разлика, че вместо differentFuel слагаш fuel (който си взимаш от commandSplit[2]). Това ти е цялата философия за нужните промени. smiley Пиши, ако искаш, дали се е получило за 100/100.

 

Успех!

2
krum_43 avatar krum_43 750 Точки

Да,мерси много.След корекциите лесно стигнах до 100/100.

 

0
svephoto avatar svephoto 1191 Точки

Екстра, така и трябваше да стане, радвам се. yes

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