算法初步——哈希表B10133.旧键盘打字 (注意bool型数组的赋值为true的方法)

 

 

 

 

#include <bits/stdc++.h>
#include<math.h>
#include <string>
using namespace std;
const int MAX_LEN = 100005;
int main(){
    //bool hashTable[256] = {true};
    memset(hashTable,true,sizeof(hashTable));
    char fir[MAX_LEN];
    char sec[MAX_LEN];
    scanf("%s",&fir);
    for(int i = 0;i<strlen(fir);++i){
        if(fir[i] >= 'A' && fir[i] <= 'Z'){
            fir[i] = fir[i] - 'A' + 'a';
        }
        hashTable[fir[i]] =  false;
    }
    scanf("%s",&sec);
    //cout<<hashTable['t'];
    for(int i = 0;i<strlen(sec);++i){
        if(sec[i]>='A' && sec[i] <= 'Z'){
            int low =  sec[i] -'A' + 'a';
            if(hashTable[low] == true && hashTable['+'] == true){
                cout<<sec[i]; 
            }
        }else if(hashTable[sec[i]] == true){
            cout<<sec[i];
        }
    }
    system("pause");
    return 0;
} 
posted @ 2020-01-06 10:07  JasonPeng1  阅读(267)  评论(0编辑  收藏  举报