HDU 4593 Robot (水题)

题意:有 n 个数,其中有两个数中相同的,让你找出这个数。

析:太简单了么,只要用数组下标记一下这个数的数量即可。

代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>


using namespace std;
const int maxn = 1e3 + 5;
int a[maxn];

int main(){
    int n;
    while(cin >> n){
        memset(a, 0, sizeof(a));
        for(int i = 0; i <= n; ++i){
            int x;
            scanf("%d", &x);
            ++a[x];
        }
        for(int i = 1; i <= n; ++i)
        if(a[i] == 2){
            printf("%d
", i);
            break;
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/dwtfukgv/p/5716301.html