http://poj.org/problem?id=1002
#include <map>
#include <iostream>
using namespace std;
map<const char, int> phonemap = {
{ 'A', 2 },
{ 'B', 2 },
{ 'C', 2 },
{ 'D', 3 },
{ 'E', 3 },
{ 'F', 3 },
{ 'G', 4 },
{ 'H', 4 },
{ 'I', 4 },
{ 'J', 5 },
{ 'K', 5 },
{ 'L', 5 },
{ 'M', 6 },
{ 'N', 6 },
{ 'O', 6 },
{ 'P', 7 },
{ 'R', 7 },
{ 'S', 7 },
{ 'T', 8 },
{ 'U', 8 },
{ 'V', 8 },
{ 'W', 9 },
{ 'X', 9 },
{ 'Y', 9 }
};
int main()
{
int num;
cin >> num;
//int phone[7 * num];
map<int, int> phones;
for (int i = 0; i < num; i++)
{
int *phone = new int[7];
int curPhoneIndex = 0;
char inputphone[16];
cin >> inputphone;
for (int i = 0; i < 16; i++)
{
if (inputphone[i] > 47 && inputphone[i] < 59)
{
phone[curPhoneIndex] = inputphone[i] - 48;
curPhoneIndex++;
}
else if (phonemap[inputphone[i]] == NULL)
{
}
else
{
phone[curPhoneIndex] = phonemap[inputphone[i]];
curPhoneIndex++;
}
}
int phonenumber = phone[0] * 1000000 + phone[1] * 100000 + phone[2] * 10000 + phone[3] * 1000 + phone[4] * 100 + phone[5] * 10 + phone[6];
if (phones.find(phonenumber) == phones.end())
{
phones.insert(map<int,int>::value_type(phonenumber, 1));
}
else
{
phones[phonenumber] += 1;
}
}
map<int,int>::iterator it = phones.begin();
bool has_count_2 = false;
for (; it != phones.end(); it++)
{
if (it->second < 2)
{
continue;
}
int i = 0;
cout << it->first / 1000000;
cout << it->first % 1000000 / 100000;
cout << it->first % 100000 / 10000;
cout << "-";
cout << it->first % 10000 / 1000;
cout << it->first % 1000 / 100;
cout << it->first % 100 / 10;
cout << it->first % 10;
cout << " " << it->second << endl;
has_count_2 = true;
}
if (!has_count_2)
{
cout << "No duplicates."<< endl;
}
return 0;
}
OJ给出的报错信息是什么呢
新的代码
#include <map>
#include <iostream>
using namespace std;
int main()
{
int num;
cin >> num;
//int phone[7 * num];
map<int, int> phones;
for (int i = 0; i < num; i++)
{
int *phone = new int[7];
int curPhoneIndex = 0;
char inputphone[16];
cin >> inputphone;
for (int i = 0; i < 16; i++)
{
if (inputphone[i] > 47 && inputphone[i] < 59)
{
phone[curPhoneIndex] = inputphone[i] - 48;
curPhoneIndex++;
}
else
{
switch (inputphone[i])
{
case 'A':case 'B':case 'C':
phone[curPhoneIndex] = 2;
curPhoneIndex++;
break;
case 'D':case 'E':case 'F':
phone[curPhoneIndex] = 3;
curPhoneIndex++;
break;
case 'G':case 'H':case 'I':
phone[curPhoneIndex] = 4;
curPhoneIndex++;
break;
case 'J':case 'K':case 'L':
phone[curPhoneIndex] = 5;
curPhoneIndex++;
break;
case 'M':case 'N':case 'O':
phone[curPhoneIndex] = 6;
curPhoneIndex++;
break;
case 'P':case 'R':case 'S':
phone[curPhoneIndex] = 7;
curPhoneIndex++;
break;
case 'T':case 'U':case 'V':
phone[curPhoneIndex] = 8;
curPhoneIndex++;
break;
case 'W':case 'X':case 'Y':
phone[curPhoneIndex] = 9;
curPhoneIndex++;
break;
default:
break;
}
}
}
int phonenumber = phone[0] * 1000000 + phone[1] * 100000 + phone[2] * 10000 + phone[3] * 1000 + phone[4] * 100 + phone[5] * 10 + phone[6];
if (phones.find(phonenumber) == phones.end())
{
phones.insert(map<int,int>::value_type(phonenumber, 1));
}
else
{
phones[phonenumber] += 1;
}
}
map<int,int>::iterator it = phones.begin();
bool has_count_2 = false;
for (; it != phones.end(); it++)
{
if (it->second < 2)
{
continue;
}
int i = 0;
cout << it->first / 1000000;
cout << it->first % 1000000 / 100000;
cout << it->first % 100000 / 10000;
cout << "-";
cout << it->first % 10000 / 1000;
cout << it->first % 1000 / 100;
cout << it->first % 100 / 10;
cout << it->first % 10;
cout << " " << it->second << endl;
has_count_2 = true;
}
if (!has_count_2)
{
cout << "No duplicates."<< endl;
}
return 0;
}