http://acm.hdu.edu.cn/showproblem.php?pid=1073这道题主要是处理字符串,将start 和 end 中的字符弄出来 ,并注意处理空行,我这里读到空行时 就用一个空格代替;
先匹配没有去掉空格和制表符的字符 相同 accept 不同才去比较处理后的字符
# include<stdio.h>
# include<stdlib.h>
# include<string.h>

char str1[5003];
char str2[5003];
char str[5003];

void fun(char *temp)


{
int len = strlen(temp),i,j;
for(j = 0,i = 0; i < len ; i ++)

{
if(temp[i]!=' '&&(temp[i]!='\t'))
temp[j++] = temp[i];
}
temp[j]='\0';
}
int main()


{
int n,i;
//freopen("in.txt","r",stdin);
scanf("%d",&n);
//fflush(stdin);
for(i = 0; i < n ; i ++)

{
while(gets(str),strcmp(str,"START")!=0)
;
gets(str1);
while(gets(str),strcmp(str,"END")!=0) //要单独处理空行

{
if(strcmp(str,"")==0)//strlen(str)==0)
strcat(str1," ");
else
strncat(str1,str,strlen(str));
}

while(gets(str),strcmp(str,"START")!=0)
;
gets(str2);
while(gets(str),strcmp(str,"END")!=0)

{
if(strcmp(str,"")==0)//strlen(str)==0)
strcat(str2," ");
else
strncat(str2,str,strlen(str));
}

if(strcmp(str1,str2)==0)
printf("Accepted\n");
else

{
fun(str1);fun(str2);
if(strcmp(str1,str2)==0)
printf("Presentation Error\n");
else
printf("Wrong Answer\n");
}

}
return 0;
}

posted on 2010-03-28 08:23
付翔 阅读(660)
评论(1) 编辑 收藏 引用 所属分类:
ACM 数据结构