ACM PKU 1002题总是WA

问题描述:

ACM PKU 1002题总是WA
各种测试数据都试过了 没有发现问题 可是C++提交上去 又是WA
#include
#include
#include
#include
using namespace::std;
string directory[100];
string result[100];
int len = 0;
int resLen = 0;
int isaTel(string &tel)
{
string::iterator pos = tel.begin();
while (pos = tel.end())
{
if ((*pos) == '-')
{
tel.erase(pos);
}
else
{
pos++;
}
}
if (tel.size() = 7)
{
return 0;
}
for (pos = tel.begin(); pos = tel.end(); pos++)
{
if isalnum(*pos))
{
return 0;
}
else
{
if (islower(*pos))
{
return 0;
}
else
{
if (*pos == 'Q' || *pos == 'Z')
{
return 0;
}
}
}
}
pos = tel.begin() + 3;
tel.insert(pos,'-');
tel += " 1";
return 1;
}
void transfer(string &tel)
{
for (int i = 0; i {
switch (tel[i])
{
case 'A':
tel[i] = '2';
break;
case 'B':
tel[i] = '2';
break;
case 'C':
tel[i] = '2';
break;
case 'D':
tel[i] = '3';
break;
case 'E':
tel[i] = '3';
break;
case 'F':
tel[i] = '3';
break;
case 'G':
tel[i] = '4';
break;
case 'H':
tel[i] = '4';
break;
case 'I':
tel[i] = '4';
break;
case 'J':
tel[i] = '5';
break;
case 'K':
tel[i] = '5';
break;
case 'L':
tel[i] = '5';
break;
case 'M':
tel[i] = '6';
break;
case 'N':
tel[i] = '6';
break;
case 'O':
tel[i] = '6';
break;
case 'P':
tel[i] = '7';
break;
case 'R':
tel[i] = '7';
break;
case 'S':
tel[i] = '7';
break;
case 'T':
tel[i] = '8';
break;
case 'U':
tel[i] = '8';
break;
case 'V':
tel[i] = '8';
break;
case 'W':
tel[i] = '9';
break;
case 'X':
tel[i] = '9';
break;
case 'Y':
tel[i] = '9';
break;
default:
break;
}
}
}
int stringCpy(const string &str1,const string &str2)
{
for (int i = 0; i {
if (str2[i] = str1[i])
{
return 0;
}
}
return 1;
}
void Add(const string &tel)
{
bool exits = false;
int i;
for (i = 0; i {
if (stringCpy(tel,directory[i]))
{
directory[i][9]++;
exits = true;
break;
}
}
if exits)
{
directory[i] = tel;
len++;
}
}
void fastDivid()
{
for (int i = 0; i {
if (directory[i][9] > '1')
{
result[resLen] = directory[i];
resLen++;
}
}
}
}
int main()
{
int num_tels;
string telnum;
cin >> num_tels;
for (int i = 0; i {
cin >> telnum;
if (isaTel(telnum))
{
transfer(telnum);
Add(telnum);
}
}
fastDivid();
sort(result,result + resLen);
for (int j = 0; j {
for (int k = 0; k {
cout

北大poj的1002,送上我丑陋的代码,夜深了,困了,睡觉去了,要是lz有疑惑,给我留言吧!(我是看的北大郭伟和李文新出的那本小红书上面的方法做的)#include using namespace std;char realnumble[100000][9];char arr[50]...