Advertisement
J00ker

(9-25)T

Sep 24th, 2014
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int a[10] = {1, 2, 3, 3, 3, 3, 3, 4, 5, 5}, n = 10, x;
  6.  
  7. int Cauta(int a[], int n, int x)
  8. {
  9. int st, dr, m;
  10. st = 0; dr = n-1;
  11. while(st <= dr)
  12. {
  13. m = (st + dr) / 2;
  14. if(a[m] == x) return m;
  15. if (a[m] < x) dr = m-1;
  16. else st = m;
  17.  
  18. }
  19. return -1;
  20. }
  21.  
  22. int Aparitii(int a[], int n, int x)
  23. {
  24. int i, st, dr, poz = Cauta(a, n, x);
  25.  
  26. for(i = poz; a[i] == x; i--);
  27. st = i+1;
  28.  
  29. for(i = poz; a[i] == x; i++);
  30. dr = i-1;
  31.  
  32. return dr - st + 1;
  33. }
  34.  
  35. int b[5] = {2, 5, 7, 10, 19}, m = 5, c[1000];
  36.  
  37. void Interclasare(int a[], int n, int b[], int m, int c[])
  38. {
  39. int k, i, j;
  40. k = i = j = 0;
  41. for(k = 0;(i < n)&&(j < m); k++)
  42. {
  43. if(a[i] <= b[j]||j == m)
  44. {
  45. c[k] = a[i];
  46. i++;
  47. }
  48. else if(a[i] > b[j]||i == n)
  49. {
  50. c[k] = b[j];
  51. j++;
  52. }
  53. }
  54. while(i < n)
  55. {
  56. c[k] = a[i];
  57. k++;
  58. i++;
  59. }
  60. while(j < m)
  61. {
  62. c[k] = b[j];
  63. k++;
  64. j++;
  65. }
  66. }
  67.  
  68. void Afisare(int a[], int n)
  69. {
  70. for(int i = 0; i < n; i++)
  71. cout << a[i] << " ";
  72. cout << "\n\n";
  73. }
  74.  
  75. int main()
  76. {
  77. cin >> x;
  78. cout << Aparitii(a, n, x) << "\n\n";
  79.  
  80. Interclasare(a, n, b, m, c);
  81. Afisare(c, m+n);
  82. cout <<a[n] << " " << b[m];
  83. return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement