1.map
試題編號: | 201412-1 |
試題名稱: | 門禁系統 |
時間限制: | 1.0s |
內存限制: | 256.0MB |
問題描述: |
問題描述
濤濤最近要負責圖書館的管理工作,需要記錄下每天讀者的到訪情況。每位讀者有一個編號,每條記錄用讀者的編號來表示。給出讀者的來訪記錄,請問每一條記錄中的讀者是第幾次出現。
輸入格式
輸入的第一行包含一個整數n,表示濤濤的記錄條數。
第二行包含n個整數,依次表示濤濤的記錄中每位讀者的編號。 輸出格式
輸出一行,包含n個整數,由空格分隔,依次表示每條記錄中的讀者編號是第幾次出現。
樣例輸入
5
1 2 1 1 3 樣例輸出
1 1 2 3 1
評測用例規模與約定
1≤n≤1,000,讀者的編號爲不超過n的正整數。
|
//@auther Yang Zongjun
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
const int MAXN = 1000+5;
map<int, int> mp;
int n, a[MAXN];
int main()
{
//freopen("input.txt", "r", stdin);
cin >> n;
for(int i = 0; i < n; i++)
cin >> a[i];
int temp;
for(int i= 0; i < n-1; i++)
{
temp = a[i];
mp[temp]++;
map<int, int>::iterator it = mp.begin();
it=mp.find(temp);
cout << it->second << " ";
}
temp = a[n-1];
mp[temp]++;
map<int, int>::iterator it = mp.begin();
it=mp.find(temp);
cout << it->second << endl;
return 0;
}