【杭电100题】2095 find your present (2)

原题:http://acm.hdu.edu.cn/showproblem.php?pid=2095

参考:http://acm.hdu.edu.cn/showproblem.php?pid=2095

为啥人家用map就过了,我用map就超时
scanf比cin的实时性好,要用scanf

#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()
{
    int n;
    map<int,int> m1;

    while(scanf("%d",&n) && n)
    {
        m1.clear();

        int b;
        while(n--)
        {
            scanf("%d",&b);
            m1[b]++;
        }
        map<int, int>::iterator iter;
        for(iter=m1.begin(); iter!=m1.end(); iter++)
        {
            if(iter->second == 1)
            {
                cout<<iter->first<<endl;
                break;
            }
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41727666/article/details/88545677