算法初步——哈希表B1039.到底买不买

#include <bits/stdc++.h>
#include<math.h>
#include <string>
using namespace std;
const int MAX_LEN = 100005;
int main(){
    int hashTable[256]; 
    for(int i=0;i<256;++i){
        hashTable[i] = 0;
    }
    char fir[1005];
    char sec[1005];
    scanf("%s",&fir);
    scanf("%s",&sec);
    for(int i =0;i<strlen(fir);++i){
        hashTable[fir[i]]++;
    }
    int cha = 0;
    int yu = 0;
    for(int i =0;i<strlen(sec);++i){
        if(hashTable[sec[i]] != 0){
            //hashTable[sec[i]]--;
            continue;
        }else{
            cha++;
        }
    }
    if(cha != 0){
        cout<<"No"<<" "<<cha;
    }else{
        /*for(int i=0;i<strlen(fir);++i){
            if(hashTable[fir[i]] != 0){
                yu += hashTable[fir[i]];
            }
        }*/
        yu = strlen(fir) - strlen(sec);
        cout<<"Yes"<<" "<<yu;
    }
    system("pause");
    return 0;
} 

原文地址:https://www.cnblogs.com/JasonPeng1/p/12156126.html