POJ 1002 487-3279
来源:互联网 发布:为什么都骂马蓉 知乎 编辑:程序博客网 时间:2024/04/30 00:44
题目链接:http://poj.org/problem?id=1002
题意:给出一串由大写字母,数字,中划线组成的字符串。其中每个大写字母对应一个数字,让你求出这串字母对应的数字串(即电话号码),要求输出的数字串的第三位与第四位中间加一个中划线。
分析:用map将字母转换成数字,将整个字符串转换成一个整数,注意这个整数有可能不是七位的(有前导0),所以在输出的时候注意一下。字符串用scanf读,否则很可能会超时。
Code:
#include <algorithm>#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <vector>#include <queue>#include <stack>#include <cmath>#include <map>#include <set>#define LL long long#define pb push_back#define pf push_front#define Max(a,b) ((a)>(b)?(a):(b))#define Min(a,b) ((a)<(b)?(a):(b))using namespace std;const int inf=0x3f3f3f3f;const int maxn=100005;int num[maxn];map<int,int>mp;map<char,int>mps;int n,cnt=0;char str[55];bool isalp(char c){ if(c>='A'&&c<='Z') return true; return false;}bool isnum(char c){ if(c>='0'&&c<='9') return true; return false;}void solve(){ int ans=0,sz=strlen(str); for(int i=0;i<sz;i++){ if(isalp(str[i])) ans=ans*10+mps[str[i]]; else if(isnum(str[i])) ans=ans*10+(str[i]-'0'); } if(!mp[ans]) num[cnt++]=ans; mp[ans]++;}int main(){ scanf("%d",&n); mps['A']=mps['B']=mps['C']=2; mps['D']=mps['E']=mps['F']=3; mps['G']=mps['H']=mps['I']=4; mps['J']=mps['K']=mps['L']=5; mps['M']=mps['N']=mps['O']=6; mps['P']=mps['R']=mps['S']=7; mps['T']=mps['U']=mps['V']=8; mps['W']=mps['X']=mps['Y']=9; while(n--){ scanf("%s",str); solve(); } sort(num,num+cnt); bool flag=false; for(int i=0;i<cnt;i++){ if(mp[num[i]]>1) { flag=true; printf("%03d-%04d %d\n",num[i]/10000,num[i]%10000,mp[num[i]]); } } if(!flag) printf("No duplicates.\n"); return 0;}
- POJ--1002 487-3279
- POJ 1002 487-3279
- POJ 1002 487-3279
- POJ 1002 487-3279
- poj 1002 "487-3279"
- POJ 1002 487-3279
- poj 1002 487-3279
- poj 1002 487-3279
- POJ-1002 487-3279
- poj 1002 487-3279
- POJ 1002 487-3279
- poj 1002 487-3279
- (POJ 1002) 487-3279
- POJ 1002 487-3279
- POJ 1002 487-3279
- [POJ]1002 487-3279
- POJ 1002 487-3279
- poj 1002 487-3279
- poj3667(线段树,区间合并)
- 背包
- 什么导致Windows XP稳占中国市场【绿色】
- virtualenv
- 【xinfanqie】迎风&&漫画win7主题_8.3
- POJ 1002 487-3279
- ContentProvider---基础总结篇之六:ContentProvider之读写联系人 .
- URAL 1019 - Line Painting
- Flex Accordion设置标题字体大小
- ContentProvider---基础总结篇之七:ContentProvider之读写短消息 .
- hdu4276 树形dp
- HDU4632:Palindrome subsequence(区间DP)
- python对CSV文件做行列变换输出
- Redis实战之Redis + Jedis