Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
A known set of the set B, and the first set of data within one unique. Seeking A, B set into a new set of C, C required in the data set are unique. And pointed out that the number of C collection.
Input
three lines, the first line A are set, the number B of
data A second set of behavioral
data of the third set of behavior B
output of
two lines of
a first row number set of the C
data of the second set of behaviors C
Sample input
. 4. 5
12 is 34 is 56 is 78
34 is 67 89 34 is 76
sample output
. 7
12 is 34 is 56 is 78 67 89 76
tips
data is less than 30,000
AC Code:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=10000;
template<class T>
struct node
{
int data;
//node<T> *r;
node<T>* next;
};
template<class T>
class lian
{
node<T> *first;
node<T> *r;
public:
lian();
lian(T a[],int n);
void cha(int a);
void show();
//void zhishan(T n);
//void weishan(int n);
};
template <class T>
lian<T>::lian()
{
first=new node<T>;
first->next=NULL;
}
template <class T>
lian<T>::lian(T a[],int n)
{
first=new node<T>;
//node<T> *r=first;
r=first;
node<T> *s=NULL;
for(int i=0;i<n;i++)
{
s=new node<T>;
s->data=a[i];
r->next=s;
r=s;
}
r->next=NULL;
}
template <class T>
void lian<T>::cha(int a)
{
node<T> *s;
s=new node<T>;
s->data=a;
node<T> *p;
p=first->next;
while(p!=NULL)
{
if(p->data==a)return;
p=p->next;
}
r->next=s;
r=s;
r->next=NULL;
}
template <class T>
void lian<T>::show()
{
node<T> *p;
p=first->next;
int t=0,h[maxn];
while(p!=NULL)
{
h[t]=p->data;
p=p->next;
t++;
}
cout<<t<<endl;
for(int i=0;i<t;i++)
{
cout<<h[i]<<" ";
}
cout<<endl;
}
int main()
{
int a[maxn],b[maxn];
int x,y;
cin>>x>>y;
for(int i=0;i<x;i++)
{
cin>>a[i];
}
for(int i=0;i<y;i++)
{
cin>>b[i];
}
lian<int> k(a,x);
for(int i=0;i<y;i++)
{
k.cha(b[i]);
}
k.show();
}