質問E:交差
2898 ワード
前言必読!http://blog.csdn.net/hnust_v/article/details/5147743問題E:交差
ソース:http://acm.hnust.edu.cn/JudgeOnline/problem.php?cid=1211&pid=4
A B, ( ), , ―― C, 。
2*n+1 , n, 2~n+1 , A 。n+2~2*n+1 , B 。
1 <= n <= 50000 , 1000000。 n 0 。
, C , C , 。 。C 。
5 1 2 5 6 7 1 2 4 6 9 0
3 1 2 6
ソース:http://acm.hnust.edu.cn/JudgeOnline/problem.php?cid=1211&pid=4
/* STL set A, B , O(n) */
#include
using namespace std;
int A[50500]={};
int main()
{
// freopen("E:\\test.txt","r",stdin);
//freopen("E:\\tsst.txt","w",stdout);
int n;
while(cin>>n&&n)
{
int Count=0;
set<int> S;
for(int i=1,a;i<=n;i++)
{
scanf("%d",&a);
S.insert(a);
}
for(int i=1,a;i<=n;i++)
{
scanf("%d",&a);
if(S.find(a)!=S.end()) A[++Count]=a;
}
if(!Count) printf("0
");
else
{
printf("%d ",Count);
for(int i=1;i<=Count;i++) printf("%d%c",A[i],i==Count?'
':' ');
}
}
return 0;
}