POJ 1002
来源:互联网 发布:淘宝入驻协议书 编辑:程序博客网 时间:2024/06/11 12:17
电话号码题,A了我一上午
本题关键是 map 数据类型的运用,mp[s]++
还有一点是 字符串的增加,只能写成 str += 的格式,我当初异想天开地以为 str = str + 也可以,后来发现太天真了。。
最后注意,输出,当没有重复的时候,记得输出 No duplicates.
#include<iostream>#include<map>#include<string>#include<string.h>using namespace std;int fun(char x){ switch(x){ 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'; default: return x; }}int main(){ int n; int len; cin>>n; char str[20]; map<string,int>mp; map<string,int>::iterator iter; for(int i=0;i<n;i++){ string s = ""; cin>>str; len = strlen(str); for(int j=0;j<len;j++) if((str[j]>='A'&&str[j]<='Z')||(str[j]>='0'&&str[j]<='9')) s += fun(str[j]); mp[s] += 1; } int counter = 1; for(iter = mp.begin();iter != mp.end();iter++){ if(iter->second>1){ counter++; for(int i=0;i<7;i++){ cout<<iter->first[i]; if(i==2) cout<<'-'; } cout<<" "<<iter->second<<endl; } } if(counter==1) cout<<"No duplicates."<<endl; return 0;}
0 0
- POJ 1002
- POJ 1002
- POJ 1002
- POJ 1002
- poj 1002
- POJ 1002
- POJ 1002
- poj 1002
- poj 1002
- POJ 1002
- POJ-1002
- poj 1002
- poj 1002
- poj 1002
- poj 1002
- poj-1002
- POJ 1002
- POJ 1002
- iOS经典讲解之倒计时按钮JKCountDownButton的使用
- Palindrome Number
- 架构基础3-网站的高可用
- 基于近邻用户协同过滤算法的音乐推荐系统
- Unity3D-启动unity事件,切换平台监听
- POJ 1002
- Python+Scrapy+Redis+Mongodb 环境安装
- oracle 函数
- 解决Android Genymotion模拟器library "/system/lib/libhoudini.so" not found报错问题
- 解决方法数超65536(java.lang.IllegalArgumentException: method ID not in [0, 0xffff]: 65536)
- FPGA 视频拼接器 动态欢迎词的实现
- split多个分隔符
- Exporting a function in a DLL using Microsoft Visual C++ 6.0
- vm中centos扩展硬盘空间