HDOJ 1563 Find your present!

来源:互联网 发布:杨君优化人生全本 编辑:程序博客网 时间:2024/05/29 11:58

Find your present!

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3356    Accepted Submission(s): 2226


Problem Description
In the new year party, everybody will get a "special present".Now it's your turn to get your special present, a lot of presents now putting on the desk, and only one of them will be yours.Each present has a card number on it, and your present's card number will be the one that different from all the others.For example, there are 5 present, and their card numbers are 1, 2, 3, 2, 1.so your present will be the one with the card number of 3, because 3 is the number that different from all the others.
 

Input
The input file will consist of several cases. 
Each case will be presented by an integer n (1<=n<=200, and n is odd) at first. Following that, n positive integers will be given in a line. These numbers indicate the card numbers of the presents.n = 0 ends the input.
 

Output
For each case, output an integer in a line, which is the card number of your present.
 

Sample Input
51 1 3 2 231 2 10
 

Sample Output
32
 

这道题就是让找只出现一次的那个号码,与2095不同之处在于此题可以用数组,把号码存到数组中,然后扫描数组,把出现的号码和号码的个数放到结构体中,结构体是号码和号码出现的次数,然后输出号码出现次数是1对应的那个号码。


AC CODE (1)  和 2095一样#includeint main(){    int n;    int x, b;    int i;    while (scanf("%d", &n), n){        b = 0;        for (i = 0; i < n; i++){            scanf("%d", &x);            b = b ^ x;        }        printf("%d\n", b);    }    return 0;}AC CODE (2)#include#includestruct NUM{    int N;    int num;}num[400];int main(){    int M,i,j,k,a[400];    while(scanf("%d",&M)&&M!=0)    {        memset(a,0,sizeof(a));        for(i=0;i        scanf("%d",&a[i]);        for(i=0;i<400;i++)            num[i].num=0;        for(i=0,j=0;i        {            if(a[i]!=-1)            num[j].N=a[i];            else continue;            for(k=0;k            if(num[j].N==a[k])            {                num[j].num+=1;                a[k]=-1;            }            j+=1;        }        for(i=0;i        if(num[i].num==1)        break;        printf("%d\n",num[i].N);    }    return 0;}


0 0
原创粉丝点击