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

相关推荐

不愿透露姓名的神秘牛友
07-04 14:23
steelhead:你回的有问题,让人感觉你就是来学习的
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-01 17:13
想去,但是听说加班强度实在难崩,所以拒绝了,现在有点心梗对面hr感觉也是实习生,打电话的时候怪紧张的,但是感觉人很好嘞
水中水之下水道的鼠鼠:哥们这不先去体验一下,不行再跑呗,大不了混个实习经历(有更好的转正offer就当我没说)
点赞 评论 收藏
分享
zhiyog:哈哈哈哈哈哈哈哈哈哈哈哈哈
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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