不能用cin>>str1>>str2的原因
cin在读取时会忽略前导和嵌入的空格、回车、制表符,如果首行是空行,cin无法识别。 getline可以识别整行,将结果保存在bad中,包括空白符。 参考
题解
主要判断两类不输出类型:
- str1中包含的str2的大写(因为str1均为大写形式,所以先将str1转换成大写)
- 大写且上档键坏了
#include <bits/stdc++.h>
using namespace std;
int main()
{
string str1,str2;
getline(cin,str1);
getline(cin,str2);
//cin>>str1>>str2;
for(int i=0;i<str2.length();i++)
{
//如果str1中找到了当前字符的大写,则不输出
char c=toupper(str2[i]);
if(str1.find(c)!=string::npos)
continue;
//如果当前字符为大写并且上档键也坏了,则也不输出
if(isupper(str2[i])&&str1.find('+')!=string::npos)
continue;
printf("%c",str2[i]);
}
return 0;
}