Saturday 2 June 2012

UVa 484 The Department of Redundancy Department Solution

#include<iostream>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<utility>
#include<iomanip>

using namespace std;
int main()
{
long long n,i,k,x;
vector<long long>name;
map<long long, long long>occ;
map<long long, long long>b;
name.clear();
occ.clear();
b.clear();
while(cin>>x)
    {
    if(b[x]!=1){
                b[x]=1;
                name.push_back(x);
                occ[x]++;
                }
    else  occ[x]++;
    }
k=name.size();
for(i=0;i<k;i++)
    {
    cout<<name[i]<<" "<<occ[name[i]]<<endl;
    }
return 0;
}

2 comments:

  1. may i know what's the b and occ for?

    ReplyDelete
  2. b to check whether the number is already taken or not, in other word, b is to check duplicate.
    occ is to count how many times the number occurred.

    ReplyDelete