有没有大神看下poj 1002为啥一直WA?

jason_ycq 2017-04-12 01:10:29
#include <iostream>
#include <map>
#include <string>

using namespace std;

void search_map(string &);
void trim(string &);
map<string, int> string_map;

int main()
{
int n;
string str;
cin >> n;
for (int i = 0; i < n; i++) {
str.clear();
cin >> str;
trim(str);
search_map(str);
}
map<string, int>::iterator itr;
for (itr = string_map.begin(); itr != string_map.end(); itr++)
if (itr->second == 1);
cout << "No duplicates." << endl;
else
cout << itr->first << " " << itr->second << endl;
return 0;
}

void search_map(string & str)
{
map<string, int>::iterator itr;
if ((itr = string_map.find(str)) != string_map.end())
itr->second++;
else
string_map.insert(pair<string, int>(str, 1));
}

void trim(string & str)
{
for (int i = 0; i < (int)str.size(); i++) {
if (str[i] == '-') {
str.erase(i, 1);
i--;
continue;
}
if (str[i] >= '0' && str[i] <= '9')
continue;
else if (str[i] < 'D') str[i] = '2';
else if (str[i] < 'G') str[i] = '3';
else if (str[i] < 'J') str[i] = '4';
else if (str[i] < 'M') str[i] = '5';
else if (str[i] < 'P') str[i] = '6';
else if (str[i] < 'T') str[i] = '7';
else if (str[i] < 'W') str[i] = '8';
else if (str[i] < 'Z') str[i] = '9';
}

str.insert(3, "-");

}
...全文
157 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jason_ycq 2017-04-12
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
边界条件 输入输出格式 ……
用的map和string应该不会越界,输出格式也和给的示例也一样的
jason_ycq 2017-04-12
  • 打赏
  • 举报
回复
我用的map和string,应该是不会越界的 输出和给出的示例也是也是一样
赵4老师 2017-04-12
  • 打赏
  • 举报
回复
边界条件 输入输出格式 ……

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧