POJ 1002LTE 答案,有时间改为数字排序

#include
#include
#include
#include
#include
using namespace std;
void outputResult(string s)
{
	cout << s << std::endl;
}
struct StringWithFlag
{
	string s;
	bool flag;
	bool operator==(StringWithFlag &other) const
	{
		if (this->s == other.s)
			return true;
		return false;
	}

	StringWithFlag(string s, bool flag)
	{
		this->s = s;
		this->flag = flag;
	}
};
int charMap[90];
int main()
{
	//字符映射表
	
	//std::memset(charMap, 0, 90 * sizeof(int));
	charMap[65] = '2'; charMap[66] = '2'; charMap[67] = '2';
	charMap[68] = '3'; charMap[69] = '3'; charMap[70] = '3';
	charMap[71] = '4'; charMap[72] = '4'; charMap[73] = '4';
	charMap[74] = '5'; charMap[75] = '5'; charMap[76] = '5';
	charMap[77] = '6'; charMap[78] = '6'; charMap[79] = '6';
	charMap[80] = '7'; charMap[82] = '7'; charMap[83] ='7';
	charMap[84] = '8'; charMap[85] = '8'; charMap[86] = '8';
	charMap[87] = '9'; charMap[88] = '9'; charMap[89] = '9';

	vector phoneVector = vector();
	vector correctedPhoneVector = vector();
	vector resultVector = vector();
	int phoneNb = 0;
	cin >> phoneNb;
	for (int index = 0; index < phoneNb; index++)
	{
		string phoneString = string();
		cin >> phoneString;
		phoneVector.push_back(phoneString);

	}
	for (vector::iterator it = phoneVector.begin(); it != phoneVector.end();)
	{
		//暂存转换后的号码数,只留数字
		string tempString = string();
		for (int strIndex = 0; strIndex < it->length(); strIndex++)
		{
			if (it->at(strIndex) == '-')
				continue;
			if (it->at(strIndex) >= '0' && it->at(strIndex) <= '9')
			{
				tempString.push_back(it->at(strIndex));
			}
			if (it->at(strIndex) >= 'A' && it->at(strIndex) <= 'Z')
			{
				tempString.push_back(charMap[(int)it->at(strIndex)]);
			}
		}
		
		correctedPhoneVector.push_back(StringWithFlag(tempString,true));
		//it = phoneVector.erase(it);
		it++;
		
	}
	size_t phoneVectorNum = correctedPhoneVector.size();
	int phoneCal = 0;
	for (vector::iterator it = correctedPhoneVector.begin(); it != correctedPhoneVector.end();)
	{
		if (it->flag == false)
		{
			continue;
		}
		phoneCal = 0;
		for (vector::iterator innerIt = correctedPhoneVector.begin(); innerIt != correctedPhoneVector.end();)
		{
			if (innerIt->flag &&*it == *innerIt)
			{
				phoneCal++;
				if (phoneCal > 1)
				{
					//innerIt = correctedPhoneVector.erase(innerIt);inner
					innerIt->flag = false;
					innerIt++;
				}
				else
				{
					innerIt++;
				}
				if (correctedPhoneVector.size() == 0)
				{
					break;
				}
			}
			else
			{
				innerIt++;
			}
			
		}
		if (phoneCal >1){
			it->s.insert(3, "-");
			string tempString = string(it->s);
			tempString.push_back(' ');
			tempString.push_back(phoneCal+'0');
			resultVector.push_back(tempString);
		}
		//it = correctedPhoneVector.erase(it);
		it->flag = false;
		it++;
		if (correctedPhoneVector.size() ==0)
		{
			break;
		}
	}
	sort(resultVector.begin(), resultVector.end());
	for_each(resultVector.begin(), resultVector.end(), outputResult);

}

你可能感兴趣的:(C++语言特性,ACM,POJ,c++)