20230402网易有道笔试之归元等计算(ac)

#include<iostream>
#include<algorithm>
#include<map>
using namespace std;

string unique_string(string s) {
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    return s;
}

int main() {
    string A;
    int n;
    while (cin >> A >> n) {
        int res = 0;
        map<string, int> m_s;
        for (int i = 0 ; i < n ; ++i) {
            string B;
            cin >> B;
            B = unique_string(B);
            if (m_s.find(B) != m_s.end())
                m_s[B]++;
            else
                m_s.insert(pair<string , int>(B , 1));
            }
        A = unique_string(A);
        for(map<string , int>::iterator it = m_s.begin() ; it != m_s.end() ; ++it){
            string temp = unique_string(A + it->first);
            int b = 0;
            if (m_s.find(temp) == m_s.end())
                continue;
            else
                b = m_s[temp];
            int a = it->second;
            if(temp == it->first)//数量为n * (n - 1)
                res += a * (a - 1);
            else//数量为n * m
                res += a * b;
        }
        cout<<res<<endl;
    }
    return 0;
}

欢迎评论区留言!!!

#网易笔试##春招笔试##悬赏#
全部评论
时间空间复杂度分析是?
点赞 回复 分享
发布于 2023-04-03 11:00 辽宁
如果能有解题思路就更好了😁
点赞 回复 分享
发布于 2023-04-03 10:27 重庆

相关推荐

不愿透露姓名的神秘牛友
07-09 11:30
找工作7个月,投了7000封,3段世界五百强实习,才有一个offer,牛油们肯定比我强吧
码农索隆:不对不对不对,实习经历这么厉害,简历也没少投,问题出在哪呢
点赞 评论 收藏
分享
06-18 13:28
已编辑
门头沟学院 Web前端
爱睡觉的冰箱哥:《给予你300的工资》,阴的没边了
点赞 评论 收藏
分享
Lorn的意义:你这种岗位在中国现在要么牛马天天加班,要么关系户进去好吃好喝,8年时间,真的天翻地覆了,对于资本来说你就说一头体力更好的牛马,哎,退伍没有包分配你真的亏了。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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