4.29 华为笔试

第一题:长度不大于8的字符串,求排列组合个数。next_permutation枚举,set去重。输入为空太坑人...
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char s[10];
    if(!cin.getline(s,10)){
        printf("0\n");
        return 0;
    }
    int l = strlen(s);
    if(l <= 0){
        printf("0\n");
        return 0;
    }
    sort(s, s+l);
    set<string> st;
    do{
        string t = "";
        for(int i = 0 ; i < l ; i++){
            t += s[i];
        }
        st.insert(t);
    }while(next_permutation(s, s+l));
    int ans = st.size();
    printf("%d\n",ans);
    return 0;
}
第二题:字符串删n个字符,求字典序最小。删掉前面比后面大的字符。如果没有,删掉最后的。用链表好删一点。
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100500
struct node{
    char c;
    node *next;
    node(char cc):c(cc),next(NULL){}
};
char s[MAXN];
int n;
int main()
{
    scanf("%s", s);
    scanf("%d",&n);
    int l = strlen(s);
    node *head = new node(' ');
    node *p = head;
    for(int i = 0 ; i < l ; i++){
        node * q = new node(s[i]);
        p->next = q;
        p = p->next;
    }
    for(int k = 0 ; k < n ; k++){
        p = head;
        while(p->next && p->next->next && (p->next->c <= p->next->next->c)){
            p = p->next;
        }
        node *q = p->next->next;
        p->next = q;
    }
    p = head->next;
    while(p){
        printf("%c", p->c);
        p = p->next;
    }
    printf("\n");
    return 0;
}
第三题:带限制条件的最短路。bfs搜索。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define MAXN 1005
struct node{
    int x,l,t;
    node(){}
    node(int xx,int ll,int tt):x(xx),l(ll),t(tt){}
    bool operator < (const node a) const{
        if(l == a.l) return t < a.t;
        return l > a.l;
    }
};
vector<node> a[MAXN];
int k,n,m;
int ans;

int main()
{
    int s,d,l,t;
    scanf("%d",&k);
    scanf("%d",&n);
    scanf("%d",&m);
    for(int i = 0 ; i < m ; i++){
        scanf("%d %d %d %d", &s, &d, &l, &t);
        s--;
        d--;
        a[s].push_back(node(d,l,t));
    }
    priority_queue<node> que;
    que.push(node(0,0,0));
    ans = -1;
    while(!que.empty()){
        node now = que.top();
        que.pop();
        if(now.x == n-1){
            ans = now.l;
            break;
        }
        for(int i = 0 ; i < a[now.x].size() ; i++){
            if(now.t + a[now.x][i].t > k)
                continue;
            que.push(node(a[now.x][i].x, now.l + a[now.x][i].l, now.t+a[now.x][i].t));
        }
    }
    printf("%d\n",ans);
    return 0;
}








#华为2020春招##笔试题目##华为#
全部评论
楼主面试了吗
点赞 回复 分享
发布于 2020-06-04 09:52
想问下a[s].push_back(node(d,l,t));是怎么个操作?a[s]不是node类型吗?为啥还可以push_back?
点赞 回复 分享
发布于 2020-05-31 00:14
楼主,您收到性格测试链接了没?
点赞 回复 分享
发布于 2020-05-11 13:46

相关推荐

不知道怎么取名字_:玩游戏都写到简历上了啊
点赞 评论 收藏
分享
最近群里有很多同学找我看简历,问问题,主要就是集中在明年三月份的暑期,我暑期还能进大厂嘛?我接下来该怎么做?对于我来说,我对于双非找实习的一个暴论就是title永远大于业务,你在大厂随随便便做点慢SQL治理加个索引,可能就能影响几千人,在小厂你从零到一搭建的系统可能只有几十个人在使用,量级是不一样的。对双非来说,最难的就是约面,怎么才能被大厂约面试?首先这需要一点运气,另外你也需要好的实习带给你的背书。有很多双非的同学在一些外包小厂待了四五个月,这样的产出有什么用呢?工厂的可视化大屏业务很广泛?产出无疑是重要的,但是得当你的实习公司到了一定的档次之后,比如你想走后端,那么中厂后端和大厂测开的选择,你可以选择中厂后端(注意,这里的中厂也得是一些人都知道的,比如哈啰,得物,b站之类,不是说人数超过500就叫中厂),只有这个时候你再去好好关注你的产出,要不就无脑大厂就完了。很多双非同学的误区就在这里,找到一份实习之后,就认为自己达到了阶段性的任务,根本不再投递简历,也不再提升自己,玩了几个月之后,美其名曰沉淀产出,真正的好产出能有多少呢?而实际上双非同学的第一份实习大部分都是工厂外包和政府外包!根本无产出可写😡😡😡!到了最后才发现晚了,所以对双非同学来说,不要放过任何一个从小到中,从中到大的机会,你得先有好的平台与title之后再考虑你的产出!因为那样你才将将能过了HR初筛!我认识一个双非同学,从浪潮到海康,每一段都呆不久,因为他在不断的投递和提升自己,最后去了美团,这才是双非应该做的,而我相信大部分的双非同学,在找到浪潮的那一刻就再也不会看八股,写算法,也不会打开ssob了,这才是你跟别人的差距。
迷茫的大四🐶:我也这样认为,title永远第一,只有名气大,才有人愿意了解你的简历
双非本科求职如何逆袭
点赞 评论 收藏
分享
评论
3
25
分享

创作者周榜

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