Advertisement
Anik_Akash

sort & find task 1

Oct 6th, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. //thanks God For Every Thing!
  2. //contest link:
  3.  
  4. //#include<bits/stdc++.h>
  5. #include<iostream>
  6. #include<string>
  7. #include<algorithm>
  8. #include<cstdio>
  9. #define pi           acose(-1)
  10. #define flush        cin.ignore(numeric_limits<streamsize>::max(),'\n');
  11. #define wow          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  12. #define NL           printf("\n")
  13.  
  14. using namespace std;
  15.  
  16. typedef long long int           ll;
  17. typedef double                  dl;
  18.  
  19. // ---------------------- slove---------------------------//
  20.  
  21. int finding(int arr[], int siz, int se);
  22.  
  23. int main()
  24. {
  25.     int n1, n2, i, j, x;
  26.     int  s1[100], s2[100], s3[100];
  27.     int a=0, b=0;
  28.  
  29.  
  30.     cout<<"Size of Array 1:"; //taking arr1 size input
  31.     cin>>n1;
  32.     flush
  33.     for( i=0; i<n1; i++)
  34.     {
  35.         cin>>s1[i];//taking arr1  input
  36.     }
  37.  
  38.     cout<<"Size of Array 2:"; //taking arr2 size input
  39.     cin>>n2;
  40.     flush
  41.     for( i=0; i<n2; i++)
  42.     {
  43.         cin>>s2[i];//taking arr2 input
  44.     }
  45.  
  46.     int se, ans;
  47.     cout<<"enter data to search : "; //taking finding number input
  48.     cin>>se;
  49.  
  50.  
  51.     //starting mearge two array
  52.     for(i=0; i<n1; i++)
  53.     {
  54.         s3[i]=s1[i];
  55.     }
  56.     int to;
  57.     to = n1+n2;
  58.  
  59.     for(i=0, x = n1; x<to, i<n2; i++, x++)
  60.     {
  61.         s3[x]=s2[i];
  62.     }
  63.     //starting sorting
  64.     sort(s3, s3+to);
  65.     cout<<"The sorted array is "<<endl;
  66.     for(i=to-1; i>=0; i--)
  67.     {
  68.         cout<<s3[i]<<" ";
  69.     }
  70.     NL;
  71.     NL;
  72.     ans = finding(s3, to, se); //finding function call;
  73.     cout<<se<<" is found "<<ans<<" times in array"<<endl;
  74.     return 0;
  75. }
  76. int finding(int arr[], int siz, int se)
  77. {
  78.     int cnt=0;
  79.     for(int i=0; i<siz; i++){
  80.         if(se == arr[i]){
  81.             cnt++;
  82.         }
  83.     }
  84.     return cnt;
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement