Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- using namespace std;
- struct car {
- string name;
- long double p;
- unsigned long d;
- unsigned long obroty;
- };
- long double fun(long double sr) {
- long double r = (sr*0.0254);
- return (r*3.141593);
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- unsigned long n;
- cin >> n;
- /*if (n == 3)
- system("pause");*/
- string _name;
- string dummy; //przechwytujący string
- long double _p;
- unsigned long _d;
- unsigned long _obroty;
- car tab_cars[3];
- //pierwsze wpisanie
- getline(cin, dummy);
- getline(cin, tab_cars[0].name);
- cin >> tab_cars[0].p >> tab_cars[0].d;
- tab_cars[0].p *= 1000; //przepisanie km na m
- tab_cars[0].obroty = floor(tab_cars[0].p / fun(tab_cars[0].d)); //obliczenie obrotów
- for (unsigned int i = 1; i < n; i++) { //początek pętli
- getline(cin, dummy); //kolejne wpisania
- getline(cin, _name);
- cin >> _p >> _d;
- _p *= 1000;
- _obroty = floor(_p / fun(_d));
- if (_obroty <= tab_cars[0].obroty) {//jeśli obroty są mniejsze lub równe pierwszemu elementowi
- if (_obroty == tab_cars[0].obroty) {
- if (_name < tab_cars[0].name) {
- tab_cars[2] = tab_cars[1];
- tab_cars[1] = tab_cars[0];
- tab_cars[0].name = _name;
- tab_cars[0].p = _p;
- tab_cars[0].d = _d;
- tab_cars[0].obroty = _obroty;
- continue;
- }
- else {
- if (_name < tab_cars[1].name && _obroty != tab_cars[1].obroty) {
- tab_cars[2] = tab_cars[1];
- tab_cars[1].name = _name;
- tab_cars[1].p = _p;
- tab_cars[1].d = _d;
- tab_cars[1].obroty = _obroty;
- continue;
- }
- else {
- if (_name < tab_cars[2].name && _obroty != tab_cars[2].obroty) {
- tab_cars[2].name = _name;
- tab_cars[2].p = _p;
- tab_cars[2].d = _d;
- tab_cars[2].obroty = _obroty;
- continue;
- }
- }
- }
- }
- else {
- tab_cars[2] = tab_cars[1];
- tab_cars[1] = tab_cars[0];
- tab_cars[0].name = _name;
- tab_cars[0].p = _p;
- tab_cars[0].d = _d;
- tab_cars[0].obroty = _obroty;
- continue;
- }
- }
- if (_obroty <= tab_cars[1].obroty) {//jeśli obroty są mniejsze lub równe drugiemu elementowi
- if (_obroty == tab_cars[1].obroty) {
- if (_name < tab_cars[1].name) {
- tab_cars[2] = tab_cars[1];
- tab_cars[1].name = _name;
- tab_cars[1].p = _p;
- tab_cars[1].d = _d;
- tab_cars[1].obroty = _obroty;
- continue;
- }
- else {
- if (_name < tab_cars[2].name && _obroty != tab_cars[2].obroty) {
- tab_cars[2].name = _name;
- tab_cars[2].p = _p;
- tab_cars[2].d = _d;
- tab_cars[2].obroty = _obroty;
- continue;
- }
- }
- }
- else {
- tab_cars[2] = tab_cars[1];
- tab_cars[1].name = _name;
- tab_cars[1].p = _p;
- tab_cars[1].d = _d;
- tab_cars[1].obroty = _obroty;
- continue;
- }
- }
- if (_obroty <= tab_cars[2].obroty) {//jeśli obroty są mniejsze lub równe trzeciemu elementowi
- if (_obroty == tab_cars[2].obroty) {
- if (toupper(_name < tab_cars[2].name)) {
- tab_cars[2].name = _name;
- tab_cars[2].p = _p;
- tab_cars[2].d = _d;
- tab_cars[2].obroty = _obroty;
- continue;
- }
- }
- else {
- tab_cars[2].name = _name;
- tab_cars[2].p = _p;
- tab_cars[2].d = _d;
- tab_cars[2].obroty = _obroty;
- continue;
- }
- }
- if (i == 1) {
- tab_cars[1].name = _name;
- tab_cars[1].p = _p;
- tab_cars[1].d = _d;
- tab_cars[1].obroty = _obroty;
- continue;
- }
- if (i == 2) {
- tab_cars[2].name = _name;
- tab_cars[2].p = _p;
- tab_cars[2].d = _d;
- tab_cars[2].obroty = _obroty;
- }
- }
- for (int i = 0; i < 3; i++) {
- cout << tab_cars[i].name << endl;
- cout << tab_cars[i].obroty << endl;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement