| ||||||||||
| 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 | |||||||||
请帮我看一下,WA是为什么呢?(附代码)#include <iostream>
#include <stdlib.h>
#include <cstring>
using namespace std;
struct STR{
char c[7];
}str[101];
int cmp ( const void *a , const void *b )
{
return strcmp( (*(STR *)a).c , (*(STR *)b).c );
}
int main(){
int i=0,j,w,n,k,t,lena,lenb;
char s[7],temp[7];
while(scanf("%s",s)){
if(s[0]=='X')break;
strcpy(str[i].c,s); //拷贝
i++;
}
n=i; //n表字典中的单词个数
qsort(str,n,sizeof(str[0]),cmp); //按字典排序
while(scanf("%s",s)){
if(s[0]=='X')break;
t=0;
for(i=0;i<n;i++){
lena=strlen(s);
lenb=strlen(str[i].c);
if(lena==lenb){ //长度相等
k=0;
if(strcmp(str[i].c,str[i+1].c)==0)++i; //排除字典中有相同的单词
strcpy(temp,s);
for(j=0;j<lenb;j++){
for(w=0;w<lena;w++){ //输入的字符串
if(temp[w]==str[i].c[j]){
k++;
temp[w]='0'; //标记
}
}
}
if(k==lena){t=1; cout<<str[i].c<<endl;}
}
}
if(t==1)cout<<"******"<<endl;
else {cout<<"NOT A VALID WORD"<<endl; cout<<"******"<<endl;}
}
system("pause");
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator