9度1351一度しか現れない数
1305 ワード
#include <cstdio>
#include <iostream>
using namespace std;
#ifdef ONLINE_JUDGE
#define FINPUT(file) 0
#define FOUTPUT(file) 0
#else
#define FINPUT(file) freopen(file,"r",stdin)
#define FOUTPUT(file) freopen(file,"w",stdout)
#endif
int firstNonZeroDigit(int t)
{
unsigned int flg = 1;
for(int i=0;i<8*sizeof(t);i++)
{
if(flg & t)
return i;
flg = flg << 1;
}
return -1;
}
int main()
{
FINPUT("in.txt");
FOUTPUT("out.txt");
int n;
while(scanf("%d",&n)!=EOF && n)
{
int i;
int *A = new int[n+1];
for(i=0;i<n;i++)
scanf("%d",&A[i]);
int c = 0;
for(i=0;i<n;i++)
c ^= A[i];
int k = firstNonZeroDigit(c);
int c1 = 0, c2 = 0;
for(i=0;i<n;i++)
{
int tt = (A[i]>>k);
if(tt&1)
c1 ^= A[i];
else
c2 ^= A[i];
}
if(c1<c2)
cout<<c1<<" "<<c2<<endl;
else
cout<<c2<<" "<<c1<<endl;
delete [] A;
}
return 0;
}