做ACM在本地能通过,但是上传总是报错Wrong Answer,题目在http://poj.org/problem?id=1002
#include<iostream>#include<map>#include<string>usingnamespacestd;stringinsert(string&...
#include <iostream>
#include <map>
#include <string>
using namespace std;
string insert(string &s1,string &s2,int n)
{
string tem(s1.begin(),s1.begin()+n);
string tem1(s1.begin()+n,s1.end());
tem+=s2;
return tem+tem1;
}
string judge(string Phone)
{
for (int j=0;j<Phone.length();j++)
{
if (Phone.at(j)>='A'&&Phone.at(j)<='C')
{
Phone[j]='2';
}
else if(Phone.at(j)>='D'&&Phone.at(j)<='F')
{
Phone[j]='3';
}
else if(Phone.at(j)>='G'&&Phone.at(j)<='I')
{
Phone[j]='4';
}
else if(Phone.at(j)>='J'&&Phone.at(j)<='L')
{
Phone[j]='5';
}
else if(Phone.at(j)>='M'&&Phone.at(j)<='O')
{
Phone[j]='6';
}
else if(Phone.at(j)>='P'&&Phone.at(j)<='S'&&Phone.at(j)!='Q')
{
Phone[j]='7';
}
else if(Phone.at(j)>='T'&&Phone.at(j)<='V')
{
Phone[j]='8';
}
else if(Phone.at(j)>='W'&&Phone.at(j)<='Y')
{
Phone[j]='9';
}
else if(Phone.at(j)>='0'&&Phone.at(j)<='9')
Phone.at(j);
}
for (int j=0;j<Phone.length();j++)
{
if(Phone[j]=='-')
{
for (int i=j+1;i<Phone.length();i++)
{
Phone[i-1]=Phone[i];
}
Phone[Phone.length()-1]='\0';
}
}
string insertx="-";
Phone=insert(Phone,insertx,3);
char phonenum[9];
for(int i=0;i<8;i++)
{
phonenum[i]=Phone[i];
}
phonenum[8]='\0';
string phone1="";
phone1=(string)phonenum;
return phone1;
}
int main()
{
map<string, int> wordCount;
map<string, int> phone;
string word;
string word1;
static long num;
cin>>num;
while (num--)
{
cin>>word;
word1="";
word1=judge(word)+"\0";
++wordCount[word1];
}
int x=0;
for (map<string, int>::iterator it = wordCount.begin();it != wordCount.end(); ++it)
{
if ((*it).second>1)
{
cout<<(*it).first<<" "<<(*it).second<<endl;
x=1;
}
}
if(x==0)
cout<<"No duplicates."<<endl;
return 0;} 展开
#include <map>
#include <string>
using namespace std;
string insert(string &s1,string &s2,int n)
{
string tem(s1.begin(),s1.begin()+n);
string tem1(s1.begin()+n,s1.end());
tem+=s2;
return tem+tem1;
}
string judge(string Phone)
{
for (int j=0;j<Phone.length();j++)
{
if (Phone.at(j)>='A'&&Phone.at(j)<='C')
{
Phone[j]='2';
}
else if(Phone.at(j)>='D'&&Phone.at(j)<='F')
{
Phone[j]='3';
}
else if(Phone.at(j)>='G'&&Phone.at(j)<='I')
{
Phone[j]='4';
}
else if(Phone.at(j)>='J'&&Phone.at(j)<='L')
{
Phone[j]='5';
}
else if(Phone.at(j)>='M'&&Phone.at(j)<='O')
{
Phone[j]='6';
}
else if(Phone.at(j)>='P'&&Phone.at(j)<='S'&&Phone.at(j)!='Q')
{
Phone[j]='7';
}
else if(Phone.at(j)>='T'&&Phone.at(j)<='V')
{
Phone[j]='8';
}
else if(Phone.at(j)>='W'&&Phone.at(j)<='Y')
{
Phone[j]='9';
}
else if(Phone.at(j)>='0'&&Phone.at(j)<='9')
Phone.at(j);
}
for (int j=0;j<Phone.length();j++)
{
if(Phone[j]=='-')
{
for (int i=j+1;i<Phone.length();i++)
{
Phone[i-1]=Phone[i];
}
Phone[Phone.length()-1]='\0';
}
}
string insertx="-";
Phone=insert(Phone,insertx,3);
char phonenum[9];
for(int i=0;i<8;i++)
{
phonenum[i]=Phone[i];
}
phonenum[8]='\0';
string phone1="";
phone1=(string)phonenum;
return phone1;
}
int main()
{
map<string, int> wordCount;
map<string, int> phone;
string word;
string word1;
static long num;
cin>>num;
while (num--)
{
cin>>word;
word1="";
word1=judge(word)+"\0";
++wordCount[word1];
}
int x=0;
for (map<string, int>::iterator it = wordCount.begin();it != wordCount.end(); ++it)
{
if ((*it).second>1)
{
cout<<(*it).first<<" "<<(*it).second<<endl;
x=1;
}
}
if(x==0)
cout<<"No duplicates."<<endl;
return 0;} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询