PAT乙级1033 运行超时怎么办?赶紧看过来~
为了避免运行超时
①选用gets函数读取整个字符串
②将字符串的长度存为变量L,避免每次判断都要计算一次
③使用strchr函数判断某字符是否在字符串中
简约精练的代码如下嘻嘻嘻~(得意_)
#include<stdio.h>
#include<string.h>
int check(char *p,char q)//能够被打出返回0
{
if(strchr(p,q)!=NULL) return 1;
else if(q>='A'&&q<='Z')
{if(strchr(p,'+')!=NULL) return 1;
if(strchr(p,q+'a'-'A')!=NULL) return 1; }
else if(q>='a'&&q<='z')
{if(strchr(p,q+'A'-'a')!=NULL) return 1; }
return 0;
}
main()
{
char ch[100001],word[100001];int i=0;//temp标记+键是否坏掉
gets(ch);gets(word);
int L=strlen(word);
for(i=0;i<L;i++)
{if(!check(ch,word[i])) printf("%c",word[i]);}
}