| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
1451...高手帮忙瞧瞧。。总是WA 。。#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
const string ss[] = {"", "","abc", "def", "ghi","jkl","mno","pqrs","tuv","wxyz"};
class A{
public:
string word;
string turned;
int prb;
A(){}
A(string s, string s2, int n){word = s; turned = s2; prb = n;}
};
bool operator < (A a1, A a2)
{
if(a1.prb > a2.prb )return 1;
if(a1.prb < a2.prb )return 0;
if(a1.word < a2.word )return 1;
else return 0;
}
A dic[1001];
int len;
string turn(string s)
{
for(int i=0; i<s.size(); ++i)
{
for(int j=2;j<=9;++j)
if(ss[j].find(s[i])!=string::npos)
{
s[i] = char(j + '0');
break;
}
}
return s;
}
bool Right(string s1, string s2)
{
if(s1.size()>s2.size())return 0;
int i;
for(i=0;i<s1.size();++i)
if(s1[i]!=s2[i])break;
if(i==s1.size())return 1;
else return 0;
}
void ope(string s)
{
int i, j;
string sss = "";
for(i=0; i<s.size()-1; ++i)
{
sss += s[i];
for(j=0;j<len;++j)
{
if(Right(sss, dic[j].turned))
{
cout<<dic[j].word.substr(0,sss.size())<<endl;
break;
}
}
if(j>=len)
break;
}
if(i<s.size()-1)
for(i++;i<=s.size()-1;++i)
cout<<"MANUALLY"<<endl;
}
int main(int argc, char* argv[])
{
int n, i, j, m1, m2, num;
string str, s1;
// freopen("in.txt","r",stdin);
cin>>n;
for(i=1; i<=n; ++i)
{
cin>>m1;
len = 0;
for(j=0;j<m1;++j)
{
cin>>str>>num;
s1 = turn(str);
A a(str, s1, num);
dic[len++] = a;
}
sort(dic,dic+len);
cin>>m2;
cout<<"Scenario #"<<i<<":"<<endl;
for(j=0;j<m2;++j)
{
cin>>str;
ope(str);
cout<<endl;
}
cout<<endl;
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator