典型的字符串处理问题。
刚开始用的vector,果断超时。题目本身没什么难度,只在选择容器上要考虑。
AC咯。
#include <iostream>
#include <string>
#include <iomanip>
#include <map>
using namespace std;
int nicknameToNumber(string&);
int main ()
{
int iPhoneTotal;
cin >> iPhoneTotal;
map<int, int> mPhone;
while (iPhoneTotal--)
{
string strTemp;
cin >> strTemp;
++mPhone[nicknameToNumber(strTemp)];
}
int iFlag = 0;
map<int, int>::iterator iter = mPhone.begin();
while (iter != mPhone.end())
{
if (iter->second > 1)
{
iFlag = 1;
cout << setw(3) << setfill('0') << iter->first/10000 << "-" << setw(4) << iter->first%10000 << " " << iter->second << endl;
}
iter++;
}
if (!iFlag)
{
cout << "No duplicates." << endl;
}
return 0;
}
int nicknameToNumber(string& strPhone)
{
int r = 0;
int i = 0;
while (i < strPhone.size())
{
if ('-' == strPhone[i] || 'Q' == strPhone[i] || 'Z' == strPhone[i])
{
}
else if (strPhone[i] >= 'A' && strPhone[i] <= 'P')
{
r = r * 10 + 2 + (strPhone[i] - 'A')/3;
}
else if (strPhone[i] >= 'R' && strPhone[i] <= 'Y')
{
r = r * 10 + 2 + (strPhone[i] - 'A' -1)/3;
}
else if (strPhone[i] <= '9' && strPhone[i] >= '0')
{
r = r * 10 + (strPhone[i] - '0');
}
i++;
}
return r;
}
分享到:
相关推荐
北大POJ1002-487-3279【Hash+Qsort】 解题报告+AC代码
业余爱好。所以,算法不一定好,CODING也不一定佳,效率不一定高,只是能通过online judge而已。
poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题...
#include #define PI 3.1415926 int main() { int n,i,m,arr[100]; float x,y,halfcircle; scanf("%d",&n); ... printf("Property %d: This property will begin eroding in year %d.\n",i,arr[i]);...
北大POJ3253-POJ3253-Fence Repair【STL优先队列】 解题报告+AC代码
poj 3414解题报告poj 3414解题报告poj 3414解题报告poj 3414解题报告
poj 1012解题报告poj 1012解题报告poj 1012解题报告poj 1012解题报告
poj 2329解题报告poj 2329解题报告poj 2329解题报告poj 2329解题报告
很有用的解题报告。。是acm初级提高的必备资料。。。。。
poj 1440解题报告 poj 1440解题报告 poj 1440解题报告 poj 1440解题报告
poj 3083解题报告poj 3083解题报告poj 3083解题报告poj 3083解题报告
poj 1659解题报告poj 1659解题报告poj 1659解题报告poj 1659解题报告
poj 3720解题报告poj 3720解题报告poj 3720解题报告poj 3720解题报告
poj1691解题报告 题目来源:http://acm.pku.edu.cn/JudgeOnline/showproblem?problem_id=1691(POJ No.1691) 解法: 搜索
这是北大在线测试的第1002题,方便记忆的电话号码的解题例程,题目中有一个列表,记录着许多方便记忆的电话号码。不同的方便记忆的电话号码可能对应相同的标准号码,这个程序的任务就是找到它们
poj2828解题报告,希望能帮到志同道合的算法爱好者
北大poj解题报告,希望能帮到软件工程的同学,每天一道,持之以恒,熟能生巧,与您共勉!
业余爱好。所以,算法不一定好,CODING也不一定佳,效率不一定高,只是能通过online judge而已。
不错的资源 收集了网上的一些解题报告 方便同学们学习参考
北大POJ3292-Semi-prime H-numbers 解题报告+AC代码