ZOJ Monthly, March 2018 Super Brain [模拟]
Input
Output
For each test case output one line containing one integer, indicating the integer which appears in both sequences.
Sample Input
3 3 3 1 2 5 3 4 2 38324 14122 38323 14122 1 180310 180310
Sample Output
3 14122 180310
做法
裸的模拟
1 #include<iostream> 2 using namespace std; 3 #include<cstdio> 4 #include<cstring> 5 #include<cstdlib> 6 #include<map> 7 map<int,int> maps; 8 int main(){ 9 int t; 10 void deal(); 11 scanf("%d",&t); 12 while(t--){ 13 deal(); 14 } 15 } 16 void deal(){ 17 int n; 18 maps.clear(); 19 scanf("%d",&n); 20 int ans = -1; 21 for(int i=1;i<=2*n;i++){ 22 int p; 23 scanf("%d",&p); 24 if(ans>0) 25 continue; 26 maps[p]+=1; 27 if(maps[p]==2){ 28 ans = p; 29 } 30 } 31 cout<<ans<<endl; 32 }