Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int MaxN = 100;
- int main()
- {
- //declaration
- int N;
- int K[MaxN];
- int M;
- int L[MaxN];
- int KA;
- int present[MaxN];
- int unique[MaxN];
- //input
- cin>>N;
- for (int i=0;i<N;i++) {
- cin>>K[i];
- }
- cin>>M;
- for (int j=0;j<M; j++){
- cin>>L[j];
- }
- cin>>KA;
- //first algorithm
- int cnt=0;
- for (int i=0; i<N; i++){
- if (KA == K[i]){
- cnt++;
- }
- }
- cout<<cnt<<endl;
- //second algorithm
- int Counter = 1;
- unique[0]= K[0];
- for(int i=1;i<N;i++){
- bool exists= false;
- for(int j=0; j<Counter; j++){
- if(K[i] == unique[j]){
- exists = true;
- j = Counter + 1;
- }
- }
- if(!exists){
- unique[Counter] = K[i];
- Counter = Counter + 1;
- }
- }
- cout<<Counter<<" ";
- int Counter1 = 1;
- unique[0]= L[0];
- for(int i=1;i<M;i++){
- bool exists= false;
- for(int j=0; j<Counter1; j++){
- if(L[i] == unique[j]){
- exists = true;
- j = Counter1 + 1;
- }
- }
- if(!exists){
- unique[Counter1] = L[i];
- Counter1 = Counter1 + 1;
- }
- }
- cout<<Counter1<<endl;
- //third algorithm
- for(int i=0; i<N; i++){
- for(int j=0; j<M; j++){
- if(K[i] == L[j]){
- present[i] =j+1;
- L[j] = 0;
- j = M;
- }else{
- present[i] = 0;
- }
- }
- }
- for (int i=0; i<N; i++) {
- cout<<present[i]<<" ";
- }
- cout<<endl;
- //fourth algorithm
- int cnt1 = 0;
- for (int i=0; i<N; i++) {
- if (present[i]==0)
- cnt1++;
- }
- cout<<cnt1<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement