Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int n, q, zmiana;
  6.  
  7.  
  8. int main()
  9. {
  10. cout << "Podaj ile jest czastek: ";
  11. cin >> n;
  12. cout << "\n";
  13. float tablica[n];
  14. cout << "Teraz podaj ich predkosci: ";
  15. for(int x=0;x<n;x++)
  16. {
  17. cin >> tablica[x];
  18. }
  19. //teraz sobie posortujemy
  20. do
  21. {
  22. zmiana =0;
  23. for(int x=0;x<n-1;x++)
  24. {
  25. if(tablica[x]>tablica[x+1])
  26. {
  27. int schowek;
  28. schowek = tablica[x+1];
  29. tablica[x+1]=tablica[x];
  30. tablica[x]=schowek;
  31. zmiana++;
  32. }
  33. }
  34. }
  35. while (zmiana != 0);
  36.  
  37. cout << "\n" << "Podaj ile predkosci chcesz zbadac: ";
  38. cin >> q;
  39. float predkosci[q];
  40. float liczba[q];
  41. cout << "\n";
  42. cout << "Podaj te predkosci: ";
  43. for(int x;x<q;x++)
  44. {
  45. liczba[x]=0;
  46. }
  47. for(int x=0;x<q;x++)
  48. {
  49. cin >> predkosci[x];
  50. }
  51. cout << "\n";
  52.  
  53. /*W tej petli prawdopodobnie jest blad*/
  54. /*->*/for(int x=0;x<q;x++)
  55. {
  56. int w=1;
  57. int m=1;
  58. int p=1;
  59. int k=q-1;
  60. int s=0;
  61. for(int wykonano=0;wykonano!=0;)
  62. {
  63. s=(p+k)/2;
  64. if(predkosci[x]>tablica[s])
  65. {
  66. p=s+1;
  67. }
  68. else if(predkosci[x]<tablica[s])
  69. {
  70. k=s-1;
  71. }
  72. else if(predkosci[x]==tablica[s])
  73. {
  74. for(int kolejne=0;kolejne!=0;)
  75. {
  76. liczba[x]++;
  77. if(tablica[s+w]==predkosci[x])
  78. {
  79. liczba[x]++;
  80. w++;
  81. }
  82. else if(tablica[s-m]==predkosci[x])
  83. {
  84. liczba[x]++;
  85. m++;
  86. }
  87. else
  88. {
  89. kolejne++;
  90. wykonano++;
  91. }
  92. }
  93. }
  94. else
  95. {
  96. wykonano++;
  97. }
  98. }
  99. }
  100. cout << "Te predkosci wystapily: ";
  101. for(int x=0;x<q;x++)
  102. {
  103. cout << liczba[x] << ", ";
  104. }
  105.  
  106. cout << " razy.";
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement