剛才搞了一個多鐘都出不來。
My ACed verion for PKU1002.
========================================================
#include <iostream>
#include <map>
#include <string>
#include <utility>
using namespace std;
map<string, int> msi;
char s2[9];
bool dup;
char table[27]="22233344455566677778889999";
void convert(const string& s)
{
int i, j=0;
string t;
for(i=0; i<s.size(); ++i)
{
if(j==3)
++j;
if( (s[i]>='A' && s[i]<='P') || (s[i]>='R' && s[i]<='Y'))
s2[j++]=table[s[i]-'A'];
else if(s[i]>='0' && s[i]<='9')
s2[j++] = s[i];
}
s2[3]='-';
s2[8]='\0';
t=s2;
if(msi.find(t)==msi.end())
msi.insert(make_pair(t, 1));
else
{
++msi[string(t)];
dup=true;
}
}
int main()
{
int n, i;
string s;
char str[1000];
while(cin>>n)
{
msi.clear();
dup=false;
for(i=1; i<=n; ++i)
{
//cin>>s;
scanf("%s", str);
s=str;
convert(s);
}
if(!dup)
cout<<"No duplicates."<<endl;
else
{
for(map<string, int>::const_iterator p=msi.begin(); p!=msi.end(); ++p)
{
if(p->second>1)
printf("%s %d\n", p->first.c_str(), p->second);
//cout<<p->first<<" "<<p->second<<endl;
}
}
}
return 0;
}
My ACed verion for PKU1002.
========================================================
#include <iostream>
#include <map>
#include <string>
#include <utility>
using namespace std;
map<string, int> msi;
char s2[9];
bool dup;
char table[27]="22233344455566677778889999";
void convert(const string& s)
{
int i, j=0;
string t;
for(i=0; i<s.size(); ++i)
{
if(j==3)
++j;
if( (s[i]>='A' && s[i]<='P') || (s[i]>='R' && s[i]<='Y'))
s2[j++]=table[s[i]-'A'];
else if(s[i]>='0' && s[i]<='9')
s2[j++] = s[i];
}
s2[3]='-';
s2[8]='\0';
t=s2;
if(msi.find(t)==msi.end())
msi.insert(make_pair(t, 1));
else
{
++msi[string(t)];
dup=true;
}
}
int main()
{
int n, i;
string s;
char str[1000];
while(cin>>n)
{
msi.clear();
dup=false;
for(i=1; i<=n; ++i)
{
//cin>>s;
scanf("%s", str);
s=str;
convert(s);
}
if(!dup)
cout<<"No duplicates."<<endl;
else
{
for(map<string, int>::const_iterator p=msi.begin(); p!=msi.end(); ++p)
{
if(p->second>1)
printf("%s %d\n", p->first.c_str(), p->second);
//cout<<p->first<<" "<<p->second<<endl;
}
}
}
return 0;
}
in my OJ, your source code result:
Name: "HJin" Problem ID "38"
Submit Time: 2007/8/30-02:05
G++: Compile Warning:
Line In function `void convert(const std::string&)':
Line 20: warning: comparison between signed and unsigned integer expressions
Test 1: Accepted Time = 0 ms
Test 2: Accepted Time = 20 ms
Test 3: Time Limit Exceed
────────────────
Problem ID 38
Test Result Time Limit Exceed
Total Time Null
Total Memory 280 Kb
Code Length 1373 Bytes
by 雨中飞燕 QQ:78803110 QQ讨论群:5305909
请大家不要用TC来学习C语言
C/C++算法习题(OnlineJudge):[url]http://yzfy.org/[/url]
[此贴子已经被作者于2007-8-30 2:08:31编辑过]