GJX的表白题解

简单的字符串模拟 用哈希表存下每个字符出现的次数,最后逐个比较即可
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <vector>

using namespace std;

string a, b;
int n;
int t;

int main(void)
{
    scanf("%d", &t);
    getchar();
    while(t -- )
    {
        unordered_map<char, int> h1, h2;

        getline(cin, a);
        getline(cin, b);
        for(int i = 0 ; i < a.size() ; i ++ ) h1[a[i]] ++, h2[b[i]] ++ ;

        if(h1.size() != h2.size()) printf("GJX is unhappy\n");
        else
        {
            bool success = true;
            for(auto item : h1)
            {
                if(!h2.count(item.first))
                {
                    success = false;
                    break;
                }else
                {
                    if(h1[item.first] != h2[item.first])
                    {
                        success = false;
                        break;
                    }
                }
            }
            if(success) puts("GJX is happy");
            else puts("GJX is unhappy");
        }
    }
    return 0;
}

全部评论
这样每次开一个unordered_map是不是很慢?
7 回复 分享
发布于 2020-12-08 12:53

相关推荐

看到这个内容真是闹麻了。。。。。。现在有了AI以后很多人面试都会作弊吗?&nbsp;那对老老实实面试的人岂不是不公平....
程序员牛肉:公平那是对小孩子讲的童话故事,成年人的世界只有能不能接受失败的后果。 你要是能接受面试作弊被发现之后多家公司联合永久拉黑的后果,你就搞。
你找工作的时候用AI吗?
点赞 评论 收藏
分享
爱睡觉的冰箱哥:学历不够啊兄弟,分析师都是9硕✌🏻咱搞不过他们滴
点赞 评论 收藏
分享
投递长鑫存储等公司8个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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