测试点2的问题,就是第一个字符串的输入可以是空,用gets(解决C环境)
#include<stdio.h>
int daxie(char ch)//判断大写
{
if(ch<='Z'&&ch>='A')
return 1;
return 0;
}
int xiaoxie(char ch)//判断小写
{
if(ch<='z'&&ch>='a')
return 1;
return 0;
}
int shuzi(char ch)//判断是否是数字
{
if(ch<='9'&&ch>='0')
return 1;
return 0;
}
int main()
{
char str1[100001],str2[100001],*p1=str1,*p2=str2;
int number[36]={0};//用来记录每个字符对应是否缺失
int shift=0,kongge=0,douhao=0,juhao=0,jianhao=0;//单独一个记录上档键是否确实
gets(str1);
scanf("%s",str2);
while(*p1!='\0')//遍历第一个字符串,做上相应的标记
{
if(*p1=='+') shift=1;
else if(*p1=='.') juhao=1;
else if(*p1=='_') kongge=1;
else if(*p1=='-') jianhao=1;
else if(*p1==',') douhao=1;
else if(daxie(*p1)) number[*p1-'A'+10]=1;
else if(shuzi(*p1)) number[*p1-'0']=1;
p1++;
}
while(*p2!='\0')//遍历第二个字符串,不缺失的输出
{
if(shuzi(*p2))//是数字字符
{
if(!number[*p2-'0'])//没有被标记
printf("%c",*p2);
}
else if(*p2=='.'&&!juhao) printf("%c",*p2);
else if(*p2=='_'&&!kongge) printf("%c",*p2);
else if(*p2=='-'&&!jianhao) printf("%c",*p2);
else if(*p2==','&&!douhao) printf("%c",*p2);
else if(daxie(*p2)) //大写
{
if(!shift)
if(!number[*p2-'A'+10])
printf("%c",*p2);
}
else if(xiaoxie(*p2))//小写
{
if(!number[*p2-'a'+10])
printf("%c",*p2);
}
p2++;
}
}