华为笔试题

第一题:
给一个字符串 都是16进制表示的,其中有两个需要转码 忘了那几个了 比如 AB : AB CD, AC: AC FF
例子
7 1 2 3 4 5 AB AC
输出
9 1 2 3 4 5 AB CD AC FF
需要注意的点:第一个也是16进制的,比如原来是 9  转成 10要输出 A

第二题
输入 a,b
输出 [a,b) 之间所有素数的 个位和 和 十位和 的较值
具体的看code
注意点:输入比较大,不能暴力求素数

ps 第三题题目

给n<=100个group,比如{1,2,3,4} 、{2,5}  {1,6} ,然后1 发一个消息到他所在的所有group ,然后,收到消息的转发一次,问最后多少人收到了
group长度没告诉你


第三题就a了80%

#include <iostream>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

#define MAX_N = 10010;
int no=1;
map<string,int> mp;
int get_n(string &s) {
    if(mp.count(s)) return mp[s];
    mp[s] = no++;
    return mp[s];
}

int stno;
vector<vector<int>> vvs;
vector<int> one;


void get_va(int d) {
    vvs.resize(d);
    getchar();
    for(int i=0;i<d;i++){
        string tmp;
        getline(cin,tmp);
        while(tmp.size()) {
            auto p = find(tmp.begin(),tmp.end(),',');
            if(p==tmp.end()){
                int n=get_n(tmp);
                vvs[i].push_back(n);
                if(s==stn)
                    break;
            }else{
                int pos = p-tmp.begin();
                string t =tmp.substr(0,pos);
                int n=get_n(t);
                vvs[i].push_back(n);
                tmp=tmp.substr(pos+1);
            }
        }
    }
    return ;
}

int main() {
    string s;
    int d;
    cin>>s;
    cin>>d;
    stno = get_n(s);

    get_va(d);


    vector<set<int>> dij(no);
    for(int i=0;i<d;i++) {
        for(auto sn: vvs[i]) {
            for(auto en: vvs[i]) {
                if(sn!=en) {
                    dij[sn].insert(en);
                    dij[en].insert(sn);
                }
            }
        }
    }

    vector<bool> vst(no,false);
    vector<int> st;
    for(int i : dij[stno]) {
        st.push_back(i);
        vst[i] = true;
    }

    for(auto v: st) {
        for(int i : dij[v]) {
            vst[i] = true;
        }
    }

    int ans = 0;
    for(auto v: vst) {
        if(v==true) {
            ans++;
        }
    }
    cout<<ans;

    return 0;;
}


第二题: 素数,
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

#define MAX_N  1000010
int isp[MAX_N]={0};
void cal_p(int e) {

    isp[2]=0;
    for(int i=2;i<e;i++) {
        if(isp[i]==0) {
//            cout<<i<<endl;
            for(int j=i+i;j<e;j+=i) isp[j]=1;
        }
    }
}

int main() {
    int s,e;
    cin>>s>>e;
    cal_p(e);
    int s10=0;
    int s1=0;
    for(int i=s;i<e;i++) {
        if(isp[i]==0) {
//            cout<<i<<endl;
            s1 += i%10;
            s10 += ((i%100)/10);
        }
    }
    cout<<min(s1,s10);

    return 0;;
}


第一题: 编解码,主要难点是第一个  需要做进制转换 比如10 -》16

ps 第三题题目

给n<=100个group,比如{1,2,3,4} 、{2,5}  {1,6} ,然后1 发一个消息到他所在的所有group ,然后,收到消息的转发一次,问最后多少人收到了
group长度没告诉你

#华为##笔试题目##题解#
全部评论
第一题: 编解码,主要是第一个可能为 A 需要做进制转换 什么意思啊 只A了20% 不知道问题在哪
点赞 回复
分享
发布于 2019-08-21 21:05
第三题的优化暴力 #include <iostream> #include <set> #include <string> #include <vector> #include <map> #include <algorithm> using namespace std; int no=1; map<string,int> mp; int get_n(string &s) {     if(mp.count(s)) return mp[s];     mp[s] = no++;     return mp[s]; } int stno; vector<vector<int>> vvs; vector<int> one; map<int,vector<int>> mpone; void get_va(int d) {     vvs.resize(d);     getchar();     for(int i=0;i<d;i++){         string tmp;         getline(cin,tmp);         while(tmp.size()) {             auto p = find(tmp.begin(),tmp.end(),',');             if(p==tmp.end()){                 int n=get_n(tmp); //                if(n==stno) one.push_back(i);                 if(mpone.count(n)) {                     mpone[n].push_back(i);                 }else{                     mpone[n]=vector<int>{i};                 }                 vvs[i].push_back(n);                 break;             }else{                 int pos = p-tmp.begin();                 string t =tmp.substr(0,pos);                 int n=get_n(t);                 if(mpone.count(n)) {                     mpone[n].push_back(i);                 }else{                     mpone[n]=vector<int>{i};                 }                 if(n==stno) one.push_back(i);                 vvs[i].push_back(n);                 tmp=tmp.substr(pos+1);             }         }     }     return ; } int main() {     string s;     int d;     cin>>s;     cin>>d;     stno = get_n(s);     get_va(d); //    for(auto v: mpone) { ////        for(auto n: v.second) cout<<n<<" ";cout<<endl; //    }     vector<bool> vst(no,false);     set<int> st;     for(auto v:mpone[stno]) {         for(int i : vvs[v]) {             st.insert(i);             vst[i] = true;         }     }     set<int> allk;     for(auto v: st) {         for(auto n:mpone[v]){             allk.insert(n);         }     }     for(auto n: allk) {         for(auto v: vvs[n]) {             vst[v] = true;         }     }     int ans = 0;     for(auto v: vst) {         if(v==true) {             ans++;         }     }     cout<<ans;     return 0;; }
点赞 回复
分享
发布于 2019-08-21 21:03
联想
校招火热招聘中
官网直投
并查集a了90%,不知道哪里错了
点赞 回复
分享
发布于 2019-08-21 21:04
第三题只过了10%😂. 不知道哪错了用的hash。前面两题ac了能过笔试吗
点赞 回复
分享
发布于 2019-08-21 21:07
麻痹,第一题死活只有20%,不知道哪里错了
点赞 回复
分享
发布于 2019-08-21 21:07
第一题的那个十六进制可以不做成十六进制相加,就直接得到size之后加上多出来的,用十进制转十六进制就稍微好一些。
点赞 回复
分享
发布于 2019-08-21 21:16
诶,你们什么时候投的华为,我怎么没收到笔试通知...
点赞 回复
分享
发布于 2019-08-21 21:21
请问能分享一下三道题的题目内容出来吗?
点赞 回复
分享
发布于 2019-08-21 21:46
很多都是输出第一个数字没转成16进制
点赞 回复
分享
发布于 2019-08-21 22:54
华为笔试是晚上几点开始的7点还是8点呢
点赞 回复
分享
发布于 2020-09-08 16:42

相关推荐

2 26 评论
分享
牛客网
牛客企业服务