find your present (2)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/1024 K (Java/Others)Total Submission(s): 15230 Accepted Submission(s): 5770
Each case will be presented by an integer n (1<=n<1000000, and n is odd) at first. Following that, n positive integers will be given in a line, all integers will smaller than 2^31. These numbers indicate the card numbers of the presents.n = 0 ends the input.
5 1 1 3 2 2 3 1 2 1 0
3 2use scanf to avoid Time Limit ExceededHintHint
#include<stdio.h>
int main()
{
int n,m,s;
while(scanf("%d",&n)!=EOF&&n)
{
s=0;
while(n--)
{
scanf("%d",&m);
s^=m;
}
printf("%d\n",s);
}
return 0;
}
或者还有一种普通的做法:
#include<stdio.h>
#include<iostream>
#include<map>
using namespace std;
int main()
{
map<int,int> s;
int n;
while(scanf("%d",&n)&&n)
{
s.clear();
while(n--)
{
int x;
scanf("%d",&x);
s[x]++;
}
map<int,int>::iterator i;
for(i=s.begin();i!=s.end();i++)
{
if(i->second==1)
{
printf("%d\n",i->first);
}
}
}
return 0;
}
5189



被折叠的 条评论
为什么被折叠?



