| ||||||||||
| 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 | |||||||||
我也是WR,为什么?下是代码#include<iostream>
#include<sstream>
#include<fstream>
using namespace std;///////The replacements should be written in the order of their appearance in the dictionary
//(in the first part of the input file)
int main(){
//ifstream in("SPELL.03");
//ofstream out("out.txt");
string s,ss[2048];
int n=0;
for(cin>>s;s!="#";cin>>s)
ss[n++]=s;
for(cin>>s;s!="#";cin>>s){
int k=0;
for(;k<n;k++){
if(ss[k]==s){
cout<<s<<" is correct";
break;
}
}
if(k>=n){
string sub[256];
int d=0;
cout<<s<<":";
for(k=0;k<n;k++){
string temp;
int i=0;
if(ss[k].size()==s.size()){//更换,则二者大小同
for(i=0;i<s.size();i++){
temp=s;//类初始化
int j=0;
for(;j<='z'-'a';j++){
temp[i]='a'+j;
if(temp==ss[k]){
int t=0;
for(;t<d&&temp!=sub[t];t++);
if(t>=d)cout<<' '<<temp;
sub[d++]=temp;
}
}
}
}
if(ss[k].size()==s.size()+1){//添加s.size()+1因为追加了
for(i=0;i<s.size()+1;i++){
temp=s;//类初始化
temp+='a';//尾部追加,任意字符即可,因为后面很快即被覆盖。只是开一个位置罢了
if(i!=s.size())for(int j=s.size()-1;j>=i;j--)temp[j+1]=temp[j];//后撤,i!=s.size()因为追加了
int j=0;
for(;j<='z'-'a';j++){
temp[i]='a'+j;
if(temp==ss[k]){
int t=0;
for(;t<d&&temp!=sub[t];t++);
if(t>=d)cout<<' '<<temp;
sub[d++]=temp;
}
}
}
}
if(ss[k].size()==s.size()-1){/////////删去则应该是s.size()-1
for(i=0;i<s.size();i++){
char *a=new char[s.size()-1];
for(int j=0;j<i;j++)a[j]=s[j];
for(int j=i;j<s.size();j++)a[j]=s[j+1];//堆前
temp.assign(a);/////////
if(temp==ss[k]){
int t=0;
for(;t<d&&temp!=sub[t];t++);
if(t>=d)cout<<' '<<temp;
sub[d++]=temp;
}
}
}
}
}
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