Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

有没有大神告知为啥WA

Posted by Jason_ycq at 2017-04-11 23:31:43 on Problem 1002 and last updated at 2017-04-11 23:44:20
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator