Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. const int MaxN = 100;
  5.  
  6. int main()
  7. {
  8. //declaration
  9. int N;
  10. int K[MaxN];
  11. int M;
  12. int L[MaxN];
  13. int KA;
  14. int present[MaxN];
  15. int unique[MaxN];
  16.  
  17. //input
  18. cin>>N;
  19.  
  20. for (int i=0;i<N;i++) {
  21. cin>>K[i];
  22. }
  23.  
  24. cin>>M;
  25. for (int j=0;j<M; j++){
  26. cin>>L[j];
  27. }
  28. cin>>KA;
  29.  
  30. //first algorithm
  31. int cnt=0;
  32. for (int i=0; i<N; i++){
  33. if (KA == K[i]){
  34. cnt++;
  35. }
  36. }
  37. cout<<cnt<<endl;
  38.  
  39. //second algorithm
  40. int Counter = 1;
  41. unique[0]= K[0];
  42. for(int i=1;i<N;i++){
  43. bool exists= false;
  44. for(int j=0; j<Counter; j++){
  45. if(K[i] == unique[j]){
  46. exists = true;
  47. j = Counter + 1;
  48. }
  49. }
  50.  
  51. if(!exists){
  52. unique[Counter] = K[i];
  53. Counter = Counter + 1;
  54. }
  55. }
  56.  
  57. cout<<Counter<<" ";
  58.  
  59. int Counter1 = 1;
  60. unique[0]= L[0];
  61. for(int i=1;i<M;i++){
  62. bool exists= false;
  63. for(int j=0; j<Counter1; j++){
  64. if(L[i] == unique[j]){
  65. exists = true;
  66. j = Counter1 + 1;
  67. }
  68. }
  69.  
  70. if(!exists){
  71. unique[Counter1] = L[i];
  72. Counter1 = Counter1 + 1;
  73. }
  74. }
  75.  
  76. cout<<Counter1<<endl;
  77.  
  78.  
  79. //third algorithm
  80. for(int i=0; i<N; i++){
  81. for(int j=0; j<M; j++){
  82. if(K[i] == L[j]){
  83. present[i] =j+1;
  84. L[j] = 0;
  85. j = M;
  86. }else{
  87. present[i] = 0;
  88. }
  89. }
  90. }
  91. for (int i=0; i<N; i++) {
  92. cout<<present[i]<<" ";
  93. }
  94. cout<<endl;
  95. //fourth algorithm
  96. int cnt1 = 0;
  97. for (int i=0; i<N; i++) {
  98. if (present[i]==0)
  99. cnt1++;
  100. }
  101. cout<<cnt1<<endl;
  102.  
  103. return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement