AOJ.720 丢失的学妹

缺失的学妹

考察点

STL MAP

Time Mem Len Lang
3.81s 39.1MB 0.68K G++

题意分析

给出妹子学号的个数n,给出n个学号,和n-1个学号,求在n学号中那个没有在n-1个学号中出现。
采用MAP,第一次统计所有学号,使second为1,第二次使对用的second++,即为2,之后用迭代器遍历,发现如果有一个对应的second为1的话,输出那个学号,break即可。

代码总览

/*
    Title:AOJ.720
    Author:pengwill
    Date:2016-12-15
*/
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
using namespace std;
typedef map<long long,int> mp;
mp p;
int main()
{
    cin.sync_with_stdio(false);
    cin.tie(0);
    int n;
    while(cin>>n){
        int i;
        long long t;
        for(i = 0;i<n;i++){
            cin>>t;
            p[t] ++;
        }

        for(i = 0;i<n-1;i++){
            cin>>t;
            p[t]++;
        }
        mp::iterator iter;
        for(iter = p.begin();iter!=p.end();iter++){
            if(iter->second == 1){
                cout<<iter->first<<endl;
                break;
            }
        }
        p.clear();
    }
    return 0;
}
posted @ 2016-12-15 20:37  pengwill  阅读(92)  评论(0编辑  收藏  举报