门禁系统 (201412-1)
来源:互联网 发布:风华软件 编辑:程序博客网 时间:2024/04/30 10:26
问题描述
涛涛最近要负责图书馆的管理工作,需要记录下每天读者的到访情况。每位读者有一个编号,每条记录用读者的编号来表示。给出读者的来访记录,请问每一条记录中的读者是第几次出现。
输入格式
输入的第一行包含一个整数n,表示涛涛的记录条数。
第二行包含n个整数,依次表示涛涛的记录中每位读者的编号。
第二行包含n个整数,依次表示涛涛的记录中每位读者的编号。
输出格式
输出一行,包含n个整数,由空格分隔,依次表示每条记录中的读者编号是第几次出现。
样例输入
5
1 2 1 1 3
1 2 1 1 3
样例输出
1 1 2 3 1
评测用例规模与约定
1≤n≤1,000,读者的编号为不超过n的正整数。
思路: 看了这道题,立马有两个思路。 第一个是用 map类型,记录每个数字 出现的次数。 第二个是用 struct类型,定义两个值,一个代表该数,另一个代表该数出现的次数。
#include <iostream>#include <map>#include <vector>using namespace std;map<int,int>m;vector<int>vec;int main(){ int n; cin>>n; int i,a; for(i=0;i<n;i++){ cin>>a; m[a]++; vec.push_back(m[a]); } vector<int>::iterator it; for(it=vec.begin();it!=vec.end();it++){ cout<<*it<<" "; } return 0;}
#include <iostream>#include <vector>using namespace std;struct per{ int a; int count;};vector<int>vec;int main(){ int n,i; cin>>n; per p[1010]; int temp; for(i=0;i<1010;i++){ p[i].a = i; p[i].count = 0; } for(i=1;i<=n;i++){ cin>>temp; ++p[temp].count; vec.push_back(p[temp].count); } vector<int>::iterator it; for(it=vec.begin();it!=vec.end();it++) cout<<*it<<" "; return 0;}
0 0
- 门禁系统 (201412-1)
- 201412-1 门禁系统
- 201412-1 门禁系统
- 201412-1门禁系统
- 201412-1 门禁系统
- CCF-门禁系统-201412-1
- CCF-201412-1 门禁系统
- CCF 201412-1 门禁系统
- CCF-201412-1-门禁系统
- CCF 201412-1 门禁系统
- ccf-201412-1 门禁系统
- ccf门禁系统201412-1
- CCF-201412-1-门禁系统
- 【ccf-201412-1】门禁系统
- 201412-1 门禁系统 ccf
- CCF 201412-1 门禁系统
- CCF-CAP 201412-1 门禁系统 答案
- CCF认证201412-1 门禁系统
- maximum flow
- 用JavaScrip实现选项卡切换的效果
- MyAdapter extends BaseAdapter
- VVS(Virtual Visual Servoing)在单目位姿估算中的应用
- javaweb怎么用eclipse连接mysql
- 门禁系统 (201412-1)
- 自定义ListView中的分割线
- 教你怎么提高网速 最全提高网速方法
- ARM Linux的启动全过程
- TCP/IP、Http、Socket的区别
- 《新世界--灵性的觉醒》感
- 4.Java中获取当前目录的方法
- Linux内核执行流程
- 学习