Advertisement
Bumler

Untitled

Dec 17th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct adatok
  6. {
  7. int dist;
  8. int price;
  9. };
  10. //1. feladat
  11. int furthest(int N, adatok adat[])
  12. {
  13. int max = 0;
  14. for (int i = 0; i < N; i++)
  15. {
  16. if (max < adat[i].dist)
  17. {
  18. max = adat[i].dist;
  19. }
  20. }
  21. return max;
  22. }
  23.  
  24. int search(int N, adatok adat[])
  25. {
  26. int max = furthest(N, adat);
  27. int i = 0;
  28. while(adat[i].dist != max)
  29. {
  30. i++;
  31. }
  32. return i+1; //A megodásban 0.tól kell indexelni !!!
  33. }
  34. //2. feladat
  35. int mostExpensivePrice(int N, adatok adat[])
  36. {
  37. int value = 0;
  38. for (int i = 0; i < N; i++)
  39. {
  40. if (value < adat[i].price && 1000 > adat[i].dist)
  41. {
  42. value = adat[i].price;
  43. }
  44. }
  45. if (value == 0)
  46. {
  47. value = -1;
  48. }
  49. return value;
  50. }
  51. //3.feladat
  52. bool isOnly(int N, int x, adatok adat[]) //egyedül van??
  53. {
  54. bool exist = true;
  55. int h = 0;
  56. for (int i = 0; i < N; i++)
  57. {
  58. if (adat[i].price == adat[x].price && i !=x)
  59. {
  60. h++;
  61. }
  62. }
  63. if (h > 0)
  64. {
  65. exist = false;
  66. }
  67. return exist;
  68. }
  69.  
  70. int obvDist(int N, adatok adat[]) //egyértelmű távolság
  71. {
  72. int ones = 0;
  73. for (int i = 0; i < N; i++)
  74. {
  75. bool x = isOnly (N, i, adat);
  76. if (x)
  77. {
  78. ones++;
  79. }
  80. }
  81. return ones;
  82. }
  83. //4.feladat
  84. int pricePerKm(int N, int x, adatok adat[])
  85. {
  86. int priceKm = adat[x].price / adat[x].dist;
  87. return priceKm;
  88. }
  89.  
  90. int moreThanHundred(int N, adatok adat[])
  91. {
  92. int amo = 0;
  93. for (int i = 0; i < N; i++)
  94. {
  95. if(pricePerKm (N, i, adat) > 100)
  96. {
  97. amo++;
  98. }
  99. }
  100. return amo;
  101. }
  102.  
  103. void expensive(int N, adatok adat[])
  104. {
  105. int amo = moreThanHundred (N, adat);
  106. cerr << "Negyedik: darab+sorszam, ha tobb mint 100 ft: ";
  107. cout << amo;
  108. for (int i = 0; i < N; i++)
  109. {
  110. if(pricePerKm (N, i, adat) > 100)
  111. {
  112. cerr << " ";
  113. cout << i+1;
  114. }
  115. }
  116. }
  117.  
  118. int main ()
  119. {
  120. //DIST PRICE
  121. int N;
  122. cin >> N;
  123. adatok adat[N];
  124. for (int i = 0; i < N; i++)
  125. {
  126. cin >> adat[i].dist >> adat[i].price;
  127. }
  128. int elso = search (N, adat);
  129. int masodik = mostExpensivePrice (N, adat);
  130. int harmadik = obvDist (N, adat);
  131. cerr << "Elso: legtavolabbi varos sorszama: " ;cout << elso << "\n";
  132. cerr << "Masodik: 1000 kilometernel kozelebbi varosok kozul a legdragabb ar: " ;cout << masodik << "\n";
  133. cerr << "Harmadik: egyertelmu varos tavolsagok szama: " ;cout << harmadik << "\n";
  134. expensive(N, adat);
  135. return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement