您的位置:首页 > 其它

POJ - 1002 487-3279

2016-02-24 19:56 381 查看

1.题面

http://poj.org/problem?id=1002

2.解题思路

这道题目我是做过的,这次居然没做出来,天哪,好像是因为人太困了写的时候出现了无数个BUG,比如在嵌套的循环中两层for都使用了i作为变量

然后,这道题目并不难,只是有些繁琐,做好了字母到数字之间的映射之后,要么讲将这个只有7位数的数字转化成一个int存储,要么将它用string存储

之后爱用map用map,爱用排序后计数就用排序后计数,有的是办法。

3.解题代码

/*****************************************************************
> File Name: tmp.cpp
> Author: Uncle_Sugar
> Mail: uncle_sugar@qq.com
> Created Time: 2016年02月24日 星期三 09时43分05秒
****************************************************************/
# include <cstdio>
# include <cstring>
# include <cmath>
# include <cstdlib>
# include <climits>
# include <iostream>
# include <iomanip>
# include <set>
# include <map>
# include <vector>
# include <stack>
# include <queue>
# include <algorithm>
using namespace std;

const int debug = 1;
const int size  = 5000 + 10;
typedef long long ll;

char str[size],nstr[size];
map<string,int> mp;
int charmap[500];
int main()
{
std::ios::sync_with_stdio(false);cin.tie(0);

charmap['A'] = charmap['B'] = charmap['C'] = 2;
charmap['D'] = charmap['E'] = charmap['F'] = 3;
charmap['G'] = charmap['H'] = charmap['I'] = 4;
charmap['J'] = charmap['K'] = charmap['L'] = 5;
charmap['M'] = charmap['N'] = charmap['O'] = 6;
charmap['P'] = charmap['R'] = charmap['S'] = 7;
charmap['T'] = charmap['U'] = charmap['V'] = 8;
charmap['W'] = charmap['X'] = charmap['Y'] = 9;

int i,j,k;
int n;
cin >> n;
while(n--){
cin >> str;
for (k=i=0;str[i]!='\0';i++){
if (isupper(str[i])){
nstr[k++] = charmap[str[i]] + '0';
}else if (isdigit(str[i])){
nstr[k++] = str[i];
}
if (k==3)
nstr[k++] = '-';
}
nstr[k] = '\0';
mp[nstr]++;
}
int flag = 1;
map<string,int>::iterator it;
for (it=mp.begin();it!=mp.end();it++){
if (it->second>=2){
flag = 0;
cout << it->first << ' ' << it->second << '\n';
}
}
if (flag)
cout << "No duplicates." << '\n';
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: