题意:输入坏掉的键,其中+表示大写键坏了,再下一行输入的是要输入的字符串,我们需要做的是输出在坏键的情况下应该输出的字符串;
hashtable:
#include#include //memset是cstring的函数; using namespace std; bool hashtable[256]; int main(){ memset(hashtable,true,sizeof(hashtable));//memset用于初始化,用于初始化啊结构体或者数组; string s1,s2; getline(cin,s1); for(int i=0;i ='A'&&s1[i]<='Z'){ s1[i]=s1[i]-'A'+'a';//大写变成小写,目的是为了与后面比较统一参数; } hashtable[s1[i]]=false; } getline(cin,s2); for(int i=0;i ='A'&&s2[i]<='Z'){ if(hashtable[s2[i]-'A'+'a']==true&&hashtable['+']==true){ cout< 2.利用find和cctype判断函数:
#include#include using namespace std; int main(){ int flag=0; string s1,s2; getline(cin,s1); if(s1.find('+')!=string::npos){ flag=1; } getline(cin,s2); for(int i=0;i 收获:
1.memset在string里卖弄,memset用于初始化结构体或者数组;
注意点:如果是测试点2过不去的话,就是用了cin输入s1,s2,因为测试点2是当s1为空行的情况下(即没有坏键),而cin无法接受空行,要用getline(cin,s1);
2.cctype判断函数,isupper等,如果判断是对的,返回不是true而是整型1,不是返回的是0;



