PAT1041 Be Unique

找出只出现过一次的数,用各种排序必然超时,需要用数组做hash表

Sample Input 1:
7 5 31 5 88 67 88 17
Sample Output 1:
31
Sample Input 2:
5 888 666 666 888 888
Sample Output 2:
None

#include <stdio.h>
#include <stdlib.h>
#define MAX 10000
#define MAX1 100000

int s[MAX] = {0},t[MAX1];

int main()
{
    long int i;
    long int N;
    scanf("%ld", &N);

    for (i = 0; i < N; i++)
    {
        scanf("%d",&t[i]);
        s[t[i]]++;
    }

    for (i = 0; i < N; i++)
    {
        if(s[t[i]] == 1)
            break;
    }
    if (i == N)
    {
        printf("None");
    }
    else
    {
        printf("%d", t[i]);
    }
    return 0;
}
 

猜你喜欢

转载自ppcool.iteye.com/blog/1734286