Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. struct car {
  9.     string name;
  10.     long double p;
  11.     unsigned long d;
  12.     unsigned long obroty;
  13. };
  14. long double fun(long double sr) {
  15.     long double r = (sr*0.0254);
  16.     return (r*3.141593);
  17. }
  18. int main()
  19. {
  20.     ios_base::sync_with_stdio(false);
  21.     unsigned long n;
  22.     cin >> n;
  23.     /*if (n == 3)
  24.         system("pause");*/
  25.  
  26.     string _name;
  27.     string dummy; //przechwytujący string
  28.     long double _p;
  29.     unsigned long _d;
  30.     unsigned long _obroty;
  31.  
  32.     car tab_cars[3];
  33.  
  34.     //pierwsze wpisanie
  35.     getline(cin, dummy);
  36.     getline(cin, tab_cars[0].name);
  37.     cin >> tab_cars[0].p >> tab_cars[0].d;
  38.     tab_cars[0].p *= 1000; //przepisanie km na m
  39.     tab_cars[0].obroty = floor(tab_cars[0].p / fun(tab_cars[0].d)); //obliczenie obrotów
  40.    
  41.  
  42.  
  43.     for (unsigned int i = 1; i < n; i++) { //początek pętli
  44.         getline(cin, dummy); //kolejne wpisania
  45.         getline(cin, _name);
  46.         cin >> _p >> _d;
  47.         _p *= 1000;
  48.         _obroty = floor(_p / fun(_d));
  49.  
  50.         if (_obroty <= tab_cars[0].obroty) {//jeśli obroty są mniejsze lub równe pierwszemu elementowi
  51.             if (_obroty == tab_cars[0].obroty) {
  52.                 if (_name < tab_cars[0].name) {
  53.                     tab_cars[2] = tab_cars[1];
  54.                     tab_cars[1] = tab_cars[0];
  55.                     tab_cars[0].name = _name;
  56.                     tab_cars[0].p = _p;
  57.                     tab_cars[0].d = _d;
  58.                     tab_cars[0].obroty = _obroty;
  59.                     continue;
  60.                 }
  61.                 else {
  62.                     if (_name < tab_cars[1].name && _obroty != tab_cars[1].obroty) {
  63.                         tab_cars[2] = tab_cars[1];
  64.                         tab_cars[1].name = _name;
  65.                         tab_cars[1].p = _p;
  66.                         tab_cars[1].d = _d;
  67.                         tab_cars[1].obroty = _obroty;
  68.                         continue;
  69.                     }
  70.                     else {
  71.                         if (_name < tab_cars[2].name && _obroty != tab_cars[2].obroty) {
  72.                             tab_cars[2].name = _name;
  73.                             tab_cars[2].p = _p;
  74.                             tab_cars[2].d = _d;
  75.                             tab_cars[2].obroty = _obroty;
  76.                             continue;
  77.                         }
  78.                     }
  79.                 }
  80.             }
  81.             else {
  82.                 tab_cars[2] = tab_cars[1];
  83.                 tab_cars[1] = tab_cars[0];
  84.                 tab_cars[0].name = _name;
  85.                 tab_cars[0].p = _p;
  86.                 tab_cars[0].d = _d;
  87.                 tab_cars[0].obroty = _obroty;
  88.                 continue;
  89.             }
  90.         }
  91.  
  92.         if (_obroty <= tab_cars[1].obroty) {//jeśli obroty są mniejsze lub równe drugiemu elementowi
  93.             if (_obroty == tab_cars[1].obroty) {
  94.                 if (_name < tab_cars[1].name) {
  95.                     tab_cars[2] = tab_cars[1];
  96.                     tab_cars[1].name = _name;
  97.                     tab_cars[1].p = _p;
  98.                     tab_cars[1].d = _d;
  99.                     tab_cars[1].obroty = _obroty;
  100.                     continue;
  101.                 }
  102.                 else {
  103.                     if (_name < tab_cars[2].name && _obroty != tab_cars[2].obroty) {
  104.                         tab_cars[2].name = _name;
  105.                         tab_cars[2].p = _p;
  106.                         tab_cars[2].d = _d;
  107.                         tab_cars[2].obroty = _obroty;
  108.                         continue;
  109.                     }
  110.                 }
  111.             }
  112.             else {
  113.                 tab_cars[2] = tab_cars[1];
  114.                 tab_cars[1].name = _name;
  115.                 tab_cars[1].p = _p;
  116.                 tab_cars[1].d = _d;
  117.                 tab_cars[1].obroty = _obroty;
  118.                 continue;
  119.             }
  120.         }
  121.  
  122.         if (_obroty <= tab_cars[2].obroty) {//jeśli obroty są mniejsze lub równe trzeciemu elementowi
  123.             if (_obroty == tab_cars[2].obroty) {
  124.                 if (toupper(_name < tab_cars[2].name)) {
  125.                     tab_cars[2].name = _name;
  126.                     tab_cars[2].p = _p;
  127.                     tab_cars[2].d = _d;
  128.                     tab_cars[2].obroty = _obroty;
  129.                     continue;
  130.                 }
  131.             }
  132.             else {
  133.                 tab_cars[2].name = _name;
  134.                 tab_cars[2].p = _p;
  135.                 tab_cars[2].d = _d;
  136.                 tab_cars[2].obroty = _obroty;
  137.                 continue;
  138.             }
  139.         }
  140.  
  141.         if (i == 1) {
  142.             tab_cars[1].name = _name;
  143.             tab_cars[1].p = _p;
  144.             tab_cars[1].d = _d;
  145.             tab_cars[1].obroty = _obroty;
  146.             continue;
  147.         }
  148.         if (i == 2) {
  149.             tab_cars[2].name = _name;
  150.             tab_cars[2].p = _p;
  151.             tab_cars[2].d = _d;
  152.             tab_cars[2].obroty = _obroty;
  153.            
  154.         }
  155.     }
  156.  
  157.     for (int i = 0; i < 3; i++) {
  158.         cout << tab_cars[i].name << endl;
  159.         cout << tab_cars[i].obroty << endl;
  160.     }
  161.  
  162.     system("pause");
  163.     return 0;
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement