zoukankan      html  css  js  c++  java
  • PAT 甲级 1041. Be Unique (20) 【STL】

    题目链接

    https://www.patest.cn/contests/pat-a-practise/1041

    思路

    可以用 map 标记 每个数字的出现次数
    然后最后再 遍历一遍 找到那个 第一个 第一次出现的数字

    AC代码

    #include <cstdio>
    #include <cstring>
    #include <ctype.h>
    #include <cstdlib>
    #include <cmath>
    #include <climits>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <deque>
    #include <vector>
    #include <queue>
    #include <string>
    #include <map>
    #include <stack>
    #include <set>
    #include <numeric>
    #include <sstream>
    #include <iomanip>
    #include <limits>
    
    #define CLR(a) memset(a, 0, sizeof(a))
    #define pb push_back
    
    using namespace std;
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    typedef pair <int, int> pii;
    typedef pair <ll, ll> pll;
    typedef pair<string, int> psi;
    typedef pair<string, string> pss;
    
    const double PI = 3.14159265358979323846264338327;
    const double E = exp(1);
    const double eps = 1e-30;
    
    const int INF = 0x3f3f3f3f;
    const int maxn = 1e5 + 5;
    const int MOD = 1e9 + 7;
    
    int main()
    {
        int n, num;
        scanf("%d", &n);
        map <int, int> m;
        vector <int> ans;
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &num);
            m[num]++;
            if (m[num] == 1)
                ans.pb(num);
        }
        vector <int>::iterator it;
        for (it = ans.begin(); it != ans.end(); it++)
        {
            if (m[*it] == 1)
            {
                printf("%d
    ", *it);
                break;
            }
        }
        if (it == ans.end())
            printf("None
    ");
    }
    
    
    
    
    
    
    
  • 相关阅读:
    最小瓶颈路
    HASH处理KMP算法
    忠诚
    程序自动分析
    图书管理
    银牛派对
    平均数
    抓住那头牛
    P2135 方块消除
    CSPS前最后一次模拟赛----爆炸的全过程
  • 原文地址:https://www.cnblogs.com/Dup4/p/9433196.html
Copyright © 2011-2022 走看看