daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest May 16th, 2018 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct lakas_adat
  6. {
  7.   int alapterulet;
  8.   int ar;
  9. };
  10.  
  11. lakas_adat* adat_olvasas(const int db);
  12. void a(const int db, const lakas_adat* adat);
  13. void b(const int db, const lakas_adat* adat);
  14. void c(const int db, const lakas_adat* adat);
  15. void d(const int db, const lakas_adat* adat);
  16. bool contains(const int db, const int* adat, const int alapterulet);
  17. void buborek_rendezes(const int db, int*& elemek);
  18.  
  19. int main()
  20. {
  21.   int db = 0;
  22.   cin >> db;
  23.   lakas_adat* adatok = adat_olvasas(db);
  24.  
  25.   a(db,adatok);
  26.   b(db,adatok);
  27.   c(db,adatok);
  28.   d(db,adatok);
  29. }
  30.  
  31. lakas_adat* adat_olvasas(const int db)
  32. {
  33.   lakas_adat* result = new lakas_adat[db];
  34.   for(int i = 0; i < db; ++i)
  35.   {
  36.     cin >> result[i].alapterulet;
  37.     cin >> result[i].ar;
  38.   }
  39.   return result;
  40. }
  41.  
  42. void a(const int db, const lakas_adat* adat)
  43. {
  44.   int index = 0;
  45.   int max = adat[0].ar;
  46.   for(int i = 1; i < db; ++i)
  47.   {
  48.     if(adat[i].ar > max)
  49.     {
  50.       max = adat[i].ar;
  51.       index = i;
  52.     }
  53.   }
  54.   cout << index + 1<< endl;
  55. }
  56.  
  57. void b(const int db, const lakas_adat* adat)
  58. {
  59.   int counter = 0;
  60.   for(int i = 0; i < db; ++i)
  61.   {
  62.     if(adat[i].alapterulet > 100)
  63.     {
  64.       if(adat[i].ar > 40)
  65.       {
  66.         ++counter;
  67.       }
  68.     }
  69.   }
  70.   cout << counter << endl;
  71. }
  72.  
  73. bool contains(const int db, const int* adat, const int alapterulet)
  74. {
  75.   for(int i = 0; i < db; ++i)
  76.   {
  77.     if(adat[i] == alapterulet) return true;
  78.   }
  79.   return false;
  80. }
  81.  
  82. void c(const int db, const lakas_adat* adat)
  83. {
  84.   int* valasztek = new int[db];
  85.   int counter = 0;
  86.   for(int i = 0; i < db; ++i)
  87.   {
  88.     if(!contains(counter,valasztek,adat[i].alapterulet))
  89.     {
  90.       valasztek[counter++] = adat[i].alapterulet;
  91.     }
  92.   }
  93.   cout << counter << endl;
  94. }
  95.  
  96. void buborek_rendezes(const int db, int*& elemek)
  97. {
  98.   for(int j = db; j > 1; --j)
  99.   {
  100.     for(int i = 0; i < j-1; ++i)
  101.     {
  102.       if(elemek[i] > elemek[i+1])
  103.       {
  104.         int tmp = elemek[i+1];
  105.         elemek[i+1] = elemek[i];
  106.         elemek[i] = tmp;
  107.       }
  108.     }
  109.   }
  110. }
  111.  
  112. void d(const int db, const lakas_adat* adat)
  113. {
  114.   int* lakasok = new int[db];
  115.   int counter = 0;
  116.   for(int i = 0; i < db; ++i)
  117.   {
  118.     if(adat[i].ar > 100)
  119.     {
  120.       lakasok[counter++] = i;
  121.     }
  122.   }
  123.   buborek_rendezes(counter,lakasok);
  124.   cout << counter;
  125.   for(int i = 0; i < counter; ++i)
  126.   {
  127.     cout << " " << lakasok[i];
  128.   }
  129.   cout << endl;
  130. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top