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 重庆

相关推荐

码农索隆:这种hr,建议全中国推广
点赞 评论 收藏
分享
叶扰云倾:进度更新,现在阿里云面完3面了,感觉3面答得还行,基本都答上了,自己熟悉的地方也说的比较细致,但感觉面试官有点心不在焉不知道是不是不想要我了,求阿里收留,我直接秒到岗当阿里孝子,学校那边的房子都退租了,下学期都不回学校,全职猛猛实习半年。这种条件还不诱人吗难道 然后现在约到了字节的一面和淘天的复活赛,外加猿辅导。华为笔试完没动静。 美团那边之前投了个base广州的,把我流程卡麻了,应该是不怎么招人,我直接简历挂了,现在进了一个正常的后端流程,还在筛选,不知道还有没有hc。
点赞 评论 收藏
分享
xdm怎么说&nbsp;要被拷打了&nbsp;担心是KPI
丹田:面就完了,就当日薪四位数的大佬免费给给你面试。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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