Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int a[10] = {1, 2, 3, 3, 3, 3, 3, 4, 5, 5}, n = 10, x;
- int Cauta(int a[], int n, int x)
- {
- int st, dr, m;
- st = 0; dr = n-1;
- while(st <= dr)
- {
- m = (st + dr) / 2;
- if(a[m] == x) return m;
- if (a[m] < x) dr = m-1;
- else st = m;
- }
- return -1;
- }
- int Aparitii(int a[], int n, int x)
- {
- int i, st, dr, poz = Cauta(a, n, x);
- for(i = poz; a[i] == x; i--);
- st = i+1;
- for(i = poz; a[i] == x; i++);
- dr = i-1;
- return dr - st + 1;
- }
- int b[5] = {2, 5, 7, 10, 19}, m = 5, c[1000];
- void Interclasare(int a[], int n, int b[], int m, int c[])
- {
- int k, i, j;
- k = i = j = 0;
- for(k = 0;(i < n)&&(j < m); k++)
- {
- if(a[i] <= b[j]||j == m)
- {
- c[k] = a[i];
- i++;
- }
- else if(a[i] > b[j]||i == n)
- {
- c[k] = b[j];
- j++;
- }
- }
- while(i < n)
- {
- c[k] = a[i];
- k++;
- i++;
- }
- while(j < m)
- {
- c[k] = b[j];
- k++;
- j++;
- }
- }
- void Afisare(int a[], int n)
- {
- for(int i = 0; i < n; i++)
- cout << a[i] << " ";
- cout << "\n\n";
- }
- int main()
- {
- cin >> x;
- cout << Aparitii(a, n, x) << "\n\n";
- Interclasare(a, n, b, m, c);
- Afisare(c, m+n);
- cout <<a[n] << " " << b[m];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement