本文主要是介绍POJ - 1002 487-3279,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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;
}
这篇关于POJ - 1002 487-3279的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!