| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
有没有大神告知为啥WA#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, "-");
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator