POJ1002-487-3279
来源:互联网 发布:湖南辉达 知乎 编辑:程序博客网 时间:2024/06/11 18:30
- #include<iostream>
- #include<map>
- #include<string>
- using namespace std;
- char convert(char character) {
- switch (character) {
- case 'A':case 'B':case 'C': return '2';
- case 'D':case 'E':case 'F': return '3';
- case 'G':case 'H':case 'I': return '4';
- case 'J':case 'K':case 'L': return '5';
- case 'M':case 'N':case 'O': return '6';
- case 'P':case 'R':case 'S': return '7';
- case 'T':case 'U':case 'V': return '8';
- case 'W':case 'X':case 'Y': return '9';
- }
- }
- int main()
- {
- int N;
- cin >> N;
- map<string, int> count_telep;
- for (int i = 0; i < N; i++) {
- string input, tele;
- cin >> input;
- for (unsigned int j = 0; j < input.length(); j++) {
- if (tele.length() == 3) tele += '-';
- if (input[j] >= '0'&&input[j] <= '9')
- tele += input[j];
- if (input[j] >= 'A'&&input[j] <= 'Z')
- tele += convert(input[j]);
- }
- if (count_telep.count(tele) == 0)
- count_telep[tele] = 0;
- count_telep[tele] += 1;
- }
- map<string, int>::iterator iter;
- bool flag = false;
- for (iter = count_telep.begin(); iter != count_telep.end(); iter++) {
- if (iter->second > 1) {
- cout << iter->first << ' ' << iter->second<< endl;
- flag = true;
- }
- }
- if (!flag)
- cout << "No duplicates. ";
- return 0;
- }
map为方便查找,按一定顺序存储,key为string类型时按照字典排序。
遍历map的两种方式:
定义为map<int,string>的元素遍历:
map<int,string> mapsfor(int i=0;i<maps.size();i++){ string=maps[i];}定义为map<string,int>的元素遍历:
map<string,int> maps;map<string,int>::iterator iter;for(iter=maps.begin();iter!=maps.end();iter++){string=iter->first;int=iter->second;}
阅读全文
0 0
- POJ1002·487-3279
- POJ1002 487-3279
- POJ1002 487-3279
- POJ1002--487-3279
- poj1002 487-3279
- poj1002 487-3279
- POJ1002 487-3279
- poj1002 487-3279
- poj1002 487-3279(哈希)
- POJ1002 487-3279
- POJ1002--487-3279 翻译
- [c]poj1002 487-3279
- 【poj1002】487-3279
- POJ1002 487-3279
- poj1002 487-3279
- POJ1002 487-3279
- POJ1002 487-3279
- POJ1002--487-3279
- 模拟考试 9.16 (期望dp)
- 安装centos系统后启用未使用的磁盘并且分区挂载
- Xstream将对象转换成xml出现乱码问题
- [NOIP2017模拟]change
- 关于VS2017中编写程序的一些问题
- POJ1002-487-3279
- 【PAT】【Advanced Level】题解目录(按年份整理)
- 软件工程中的日志打印总结
- redis | 键的命令
- 关于 Cannot create __weak reference in file using manual reference counting及配置ReactiveCocoa
- Python安全小工具之计算文件Hash值
- CentOS 6.3配置PPTP VPN的方法
- 数据结构——时间/空间复杂度
- 19. 用 GTK+ 进行GNOME 编程,用 Qt进行KDE 编程