#Java - More Exercise: Objects and Classes - 3. Car Salesman
Привет,
Може ли малко помощ. Дава ми 20 от 100.
Output-а, гледайки по единия нулев тест е същия, но има някакви интервали, които иска judge отпред. Не разбирам, изходите ми са същите, до толкова до колкото съвпадат с тези в документа.
Решението ми в Zip, Линк за сваляне : https://dox.abv.bg/download?id=d0ecd4728a# - Линк за сваляне
Условие :
3.Car Salesman
Define two classes Car and Engine. A Car has a model, engine, weight and color. An Engine has model, power, displacement and efficiency. A Car’s weight and color and its Engine’s displacements and efficiency are optional.
On the first line, you will read a number N which will specify how many lines of engines you will receive, on each of the next N lines you will receive information about an Engine in the following format “<Model> <Power> <Displacement> <Efficiency>”. After the lines with engines, on the next line you will receive a number M – specifying the number of Cars that will follow, on each of the next M lines information about a Car will follow in the following format “<Model> <Engine> <Weight> <Color>”, where the engine in the format will be the model of an existing Engine. When creating the object for a Car, you should keep a reference to the real engine in it, instead of just the engine’s model, note that the optional properties might be missing from the formats.
Your task is to print each car (in the order you received them) and its information in the format defined bellow, if any of the optional fields has not been given print "n/a" in its place instead:
<CarModel>:
<EngineModel>:
Power: <EnginePower>
Displacement: <EngineDisplacement>
Efficiency: <EngineEfficiency>
Weight: <CarWeight>
Color: <CarColor>
Optional
Override the classes’s ToString() methods to have a reusable way of displaying the objects.
Examples
Input |
Output |
2 V8-101 220 50 V4-33 140 28 B 3 FordFocus V4-33 1300 Silver FordMustang V8-101 VolkswagenGolf V4-33 Orange |
FordFocus: V4-33: Power: 140 Displacement: 28 Efficiency: B Weight: 1300 Color: Silver FordMustang: V8-101: Power: 220 Displacement: 50 Efficiency: n/a Weight: n/a Color: n/a VolkswagenGolf: V4-33: Power: 140 Displacement: 28 Efficiency: B Weight: n/a Color: Orange |
4 DSL-10 280 B V7-55 200 35 DSL-13 305 55 A+ V7-54 190 30 D 4 FordMondeo DSL-13 Purple VolkswagenPolo V7-54 1200 Yellow VolkswagenPassat DSL-10 1375 Blue FordFusion DSL-13 |
FordMondeo: DSL-13: Power: 305 Displacement: 55 Efficiency: A+ Weight: n/a Color: Purple VolkswagenPolo: V7-54: Power: 190 Displacement: 30 Efficiency: D Weight: 1200 Color: Yellow VolkswagenPassat: DSL-10: Power: 280 Displacement: n/a Efficiency: B Weight: 1375 Color: Blue FordFusion: DSL-13: Power: 305 Displacement: 55 Efficiency: A+ Weight: n/a Color: n/a |
Ето едно решение от мен, но имай предвид, че не взема 100/100 в Judge заради Time Limit на някои от тестовете.
Целта ми беше по-изчистено решение с regex и стриймове и някои основни валидации, което се надявам да ти е по-интересно и полезно.
Много полезно дори! Благодаря!