pat 乙级 1033. 旧键盘打字(20)

来源:互联网 发布:小说改编的耽美网络剧 编辑:程序博客网 时间:2024/05/22 13:17


思路 :


定义一个count 数组 下标为ascii码  ; count[]=1 代表 为坏键 

遍历第一行输入的 坏键  , 如果是 大写字母 对应的小写字母也要标记为1 ;


接着遍历 第二行的 字符, 如果 coun[‘+’]=1 ;即如果 + 坏的话,所有的大写字母都不能输出 。


输出所有符合条件的 count[] 不为1 的即可 。



代码实现 :


#include <iostream>#include <string.h>#include<ctype.h>using namespace std;char a[100005];char b[100005];char c[200]={0}; // 用来标记键盘的键是否坏;int main(){gets(a);  // 注意这里有空格所以不要用scanf 或者cin;gets(b);int lena=strlen(a);int lenb=strlen(b);for (int j=0;j<lena ;j++ ){if (isupper(a[j])){c[a[j]-'A'+'a']=1;             // 如果是大写 对应的小写坏了 坏键存为1}c[a[j]]=1;}  // 如果有'+'所有的大写字母都不能输出int check=0;for (int i=0;i<lenb ;i++ ){if(c['+']==1){if(!isupper(b[i])&&c[b[i]]!=1){cout<<b[i];check=1;}}else {if(c[b[i]]!=1){cout<<b[i];check=1;}  }}if (check==0){cout<<endl;}return 0;}




原创粉丝点击