| ||||||||||
| 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,一道字符串判别的题LINGO,还望高手指教,谢谢!源程序如下:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(void)
{
char data[1000][10],temp[10],word[10];
char result[10];
int l,i,j,k,s,t,m,n,total,inTurn,getResult,wordwhetherUsed[5],tempwhetherUsed[5],right,upper,spaceBefore;
gets(temp);
total=0;
inTurn=0;
getResult=0;
spaceBefore=1;
while (strcmp(temp,"LINGO")!=0)
{
if (strcmp(temp,"")==0) {
if (inTurn<6 && getResult==0 && spaceBefore==0)
{
for (i=0;i<=4;i++) printf("%c",word[i]+32); // When used in the contestant gives up.
printf("\n");
}
printf("\n");
total++;
inTurn=0;
getResult=0;
spaceBefore=1;
}
else
{
spaceBefore=0;
inTurn++;
if (inTurn==6 && strcmp(temp,word)!=0) {
for (i=0;i<=4;i++) printf("%c",word[i]+32);
printf("\n");
while (strcmp(temp,"")!=0 && strcmp(temp,"LINGO")!=0)
{
gets(temp);
}
continue;
}
l=strlen(temp);
if (inTurn==1) {
strcpy(word,temp);
printf("%c....\n",word[0]);
result[0]=word[0];
for (i=1;i<=4;i++) result[i]='.';
gets(temp);
continue;
}
//----------judge whether input data is invalid
upper=0;
if (l==5) {
for (i=0;i<=4;i++) if (temp[i]>='A' && temp[i]<='Z') upper++;
}
if (l!=5 || upper!=5) {
for (i=0;i<=4;i++) printf("%c",result[i]);
printf("\n");
}
else
{
for (i=0;i<=4;i++) {
wordwhetherUsed[i]=0;
tempwhetherUsed[i]=0;
}
right=0;
for (i=0;i<=4;i++)
if (word[i]==temp[i]) {
result[i]=word[i];
wordwhetherUsed[i]=1;
tempwhetherUsed[i]=1;
right++;
}
if (right==5) {
for (i=0;i<=4;i++)
printf("%c",word[i]);
printf("\n");
getResult=1;
while (strcmp(temp,"")!=0 && strcmp(temp,"LINGO")!=0)
{
gets(temp);
}
}
else
{
for (i=0;i<=4;i++)
if (wordwhetherUsed[i]==0)
{
for (j=0;j<=4;j++)
if (tempwhetherUsed[j]==0 && word[i]==temp[j])
{
wordwhetherUsed[i]=1;
tempwhetherUsed[j]=1;
result[j]=word[i]+32;
}
}
for (i=0;i<=4;i++)
if (tempwhetherUsed[i]==0)
result[i]='.';
for (i=0;i<=4;i++)
printf("%c",result[i]);
printf("\n");
}
}
}
if (getResult==0) gets(temp);
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator