房天下 > 房天下问答 > 业主生活 > 其他
  • c++程序设计 P Number Extended Reloaded

    Description:Given a sequence b1, b2, b3… bn of even length, the occurrence of every bi (i=1, 2, 3…n) is an even number except two numbers, the P numbers, which occur odd times. Your task is to find those two P numbers.Input:The input file contains several test case, each test case starts with a line contains an even number n (0<n<10 000), the length of the sequence, followed by a line with n numbers b1, b2, b3…bn. It is guaranteed that every bi (i=1, 2, 3..,n) can be represented by a signed integer. The input is terminated by a test case with n = 0. It should not be processed. Output:For each test case, output a line the P numbers of the corresponding sequence in ascending order with a space character between the two numbers. Sample Input:62 3 2 3 4 582 2 2 2 2 2 2 90Sample Output:4 52 9

    提问者:假想的舞台剧

    发布于2011-01-18

共1个回答
  • lhrrr 丨Lv 0
    代码如下:#include<iostream> #include<string> using namespace std; void main(){ int *a; int size; int i,n,count,num,j; while(1) { num=0; size=0; cout<<"Please input N:"; cin>>size; if(size==0) break; a=new int[size]; memset(a,0,size); cout<<"Please input Nums:"<<endl; for(i=0;i<size;i++) cin>>a[i]; cout<<"Output:"<<endl; for(i=0;i<size;i++) { count=0; for(n=0;n<size;n++) { if(a[i]==a[n]) count++; } if(num==0) { if(count%2==1) { j=i; cout<<a[i]<<" "; num++; } } else if(num==1) { if(count%2==1 && a[j]!=a[i]) { cout<<a[i]<<" "; delete[] a; break; } } } cout<<endl; }}
    +1 2011-01-18 举报
热门人气推荐
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。