P137下 B1043 哈希表的应用 1092 To Buy or Not to Buy P135下 天勤

//P137下  天勤 B1043  哈希表的应用 C语言版本
#include <stdio.h>
#define maxSize 10001
int main(){
    char s[maxSize];
    int count[200] = {};
    char dic[] = "PATest";
    gets(s);
    for(int i=0;s[i]!='\0';++i)  ++count[(int)s[i]];
    while(1){
        int flag = 0;
        for(int i=0;dic[i]!='\0';++i){
            if(count[(int)dic[i]] > 0){
                printf("%c",dic[i]);
                --count[(int)dic[i]];
                flag = 1;
            }
        }
        if(flag ==0) break;
    }
    return 0;
}

//1092 To Buy&nbs***bsp;Not to Buy (20分) P135下  天勤
//关于字符映射为int  两处处理略不同
#include <stdio.h>
int main(){
    int counts[123] = {};//大于ascii值即可
    char seller[1001];
    char littleRed[1001];
    gets(seller);
    gets(littleRed);

    for(int i=0;seller[i]!='\0';++i){
        ++counts[(int)seller[i]];
    }
    for(int i=0;littleRed[i]!='\0';++i){
        --counts[(int)littleRed[i]];
    }
    int count=0;
    for(int i=0;i<123;++i){
        if(counts[i]<0) count+=counts[i];
    }
    if(count<0) printf("No %d\n",-count);
    else{
        count=0;
        for(int i=0;i<123;++i){
            if(counts[i]>0) count+=counts[i];

        }
        printf("Yes %d\n",count);
    }

    return 0;
}

全部评论

相关推荐

11-26 09:30
复旦大学 Java
点赞 评论 收藏
分享
青春运维少年不会梦到...:实习大王
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务