Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include<algorithm>
  3. using namespace std;
  4. int s(int a[],int x,int h)
  5. {
  6. int l=0;
  7. for(l=0;l<=h;l++)
  8. {
  9. if(x==a[l])
  10. return l;
  11. }
  12. return -1;
  13. }
  14. int main()
  15. {
  16. /*int a[1000];
  17. int n,x;
  18. int i;
  19. cin>>n>>x;
  20. for(i=0;i<n;i++)
  21. scanf("%d",&a[i]);
  22. sort(a,a+n);
  23. int r=s(a,x,n-1);
  24. cout<<r<<endl;*/
  25. int i,j;
  26. int cs=1,n,q;
  27. cin>>n>>q;
  28. while(n!=0&&q!=0)
  29. {
  30.  
  31. int a[10000];
  32. for(i=0;i<n;i++)
  33. {
  34. cin>>a[i];
  35. }
  36. sort(a,a+n);
  37. printf("CASE# %d:\n",cs);
  38. for(j=0;j<q;j++)
  39. {
  40. int x;
  41. cin>>x;
  42.  
  43. int r=s(a,x,n-1);
  44. // cout<<r<<endl;
  45. //cs++;
  46. if(r!=-1)
  47. {
  48. /*while(a[r]!=x)
  49. r--;*/
  50. r++;
  51. }
  52. if(r==-1)
  53. printf("%d not found\n",x);
  54. else
  55. printf("%d found at %d\n",x,r);
  56.  
  57. }
  58. cs++;
  59. cin>>n>>q;
  60. }
  61. return 0;
  62.  
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement