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 10:27 重庆
时间空间复杂度分析是?
点赞 回复 分享
发布于 2023-04-03 11:00 辽宁

相关推荐

01-02 21:17
已编辑
西安理工大学 后端
程序员小白条:项目不太重要,你的优势的算法竞赛,然后多背相关的八股文,项目可以不作为重点考虑,面试可能就简单带过项目就行了,你可以直接写简历,背项目相关的八股文就行,也不用自己做,时间紧张的情况下,性价比最高
点赞 评论 收藏
分享
coffrar:全都是已读😅沟通一千五百多个了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务