试题编号: | 201412-1 |
试题名称: | 门禁系统 |
时间限制: | 1.0s |
内存限制: | 256.0MB |
问题描述: | 问题描述 涛涛最近要负责图书馆的管理工作,需要记录下每天读者的到访情况。每位读者有一个编号,每条记录用读者的编号来表示。给出读者的来访记录,请问每一条记录中的读者是第几次出现。 输入格式 输入的第一行包含一个整数n,表示涛涛的记录条数。 输出格式 输出一行,包含n个整数,由空格分隔,依次表示每条记录中的读者编号是第几次出现。 样例输入 5 样例输出 1 1 2 3 1 评测用例规模与约定 1≤n≤1,000,读者的编号为不超过n的正整数。 |
题目分析:
记录每个输入的数字是第几次出现
第一次提交的时候,由于没看清题,输出需要一行显示
最后选择将结果存储在一个数组中;
# include<iostream>
# include<cstdio>
# include<cstdlib>
# include<cstring>
# include<string>
# include<cmath>
# include<algorithm>
using namespace std;
int book[1010];
int map[1010];
int main()
{
memset(book,0,sizeof(book));
int n,val;
scanf("%d",&n);
for(int i = 0;i < n;++i)
{
scanf("%d",&val);
book[val]++;
map[i] = book[val];
}
for(int i = 0;i < n;++i)
i == 0 ? printf("%d",map[i]) : printf(" %d",map[i]);
printf("\n");
return 0;
}