9.13百度

第一题
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s.size() < 5){
        cout<<0;
        return 0;
    }
    int count = 0;
    unordered_set<char> set1{'a','e','i','o','u','A','E','I','O','U'};
    for(int i = 0 ; i <= s.size()-5;i++){
        string ss = s.substr(i,5);
        vector<int> vec(26,0);
        bool flag = true;
        for(int  j = 0 ; j < 5;j++){
            vec[ss[j]-'a']++;
            if(vec[ss[j]-'a']  > 1){
                flag = false;
                break;
            }
        }
        if(!flag){
            continue;
        }
        if(set1.count(ss[0])||!set1.count(ss[1])||!set1.count(ss[2])||set1.count(ss[3])||!set1.count(ss[4])){
            continue;
        }
        count++;
    }
    cout<<count;
    return 0;
}
第二题
#include <bits/stdc++.h>
using namespace std;
int main(){
    int number;
    cin>>number;
    for(int i = 0 ; i < number;i++){
        string s;
        cin>>s;
        int zeronum = 0;
        int onenum = 0;
        for(int i = 0 ; i < s.size();i++){
            if(s[i] == '0'){
                zeronum++;
            }else{
                onenum++;
            }
        }
        if(onenum%2 == 0 ||zeronum %2 == 0){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}
第三题
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    if(n == 0 && m == 0){
        cout<<0;
        return 0;
    }
    vector<string> vec;
    string temp;
    for(int i = 0 ; i < n;i++){
        cin>>temp;
        vec.push_back(temp);
    }
    bool success = false;
    queue<pair<int,int>> que;
    que.push({0,0});
    vector<vector<bool>> visited(n,vector<bool>(m,false));
    visited[0][0] = true;
    vector<vector<int>> moved{{-1,0},{1,0},{0,-1},{0,1}};
    int count = 0;
    while(!que.empty()){
        int size = que.size();
        for(int i = 0 ; i < size ;i++){
            auto item = que.front();
            que.pop();
            char d = vec[item.first][item.second];
            if(item.first == n-1 && item.second == m-1){
                cout<<count;
                return 0;
            }
            visited[item.first][item.second] = true;
            for(int j = 0 ; j < 4 ; j++){
                int newx = item.first + moved[j][0];
                int newy = item.second + moved[j][1];
                if(newx >= 0 && newx < n && newy >= 0 && newy < n && visited[newx][newy] == false){
                    if(vec[item.first][item.second] == 'r'){
                        if(vec[newx][newy] == 'r'||vec[newx][newy] == 'e'){
                            que.push({newx,newy});
                            visited[newx][newy] = true;
                        }
                    }else if(vec[item.first][item.second] == 'e'){
                        if(vec[newx][newy] == 'e'||vec[newx][newy] == 'd'){
                            que.push({newx,newy});
                            visited[newx][newy] = true;
                        }
                    }else if(vec[item.first][item.second] == 'd'){
                        if(vec[newx][newy] == 'd'||vec[newx][newy] == 'r'){
                            que.push({newx,newy});
                            visited[newx][newy] = true;
                        }
                    }
                }
            }
        }
        count++;
    }
    if(!success){
        cout<<-1;
    }
    return 0;
}
百度共享中突然笔试,笔试还这难度,感觉不缺人啊,随便吧。菜鸡躺平了
#百度23秋招笔试编程题有点儿简单啊#
全部评论
楼主第三题的代码是不是没考虑最短
点赞
送花
回复
分享
发布于 2022-09-13 21:02 江苏
为啥dfs会超时
1
送花
回复
分享
发布于 2022-09-13 20:46 北京
滴滴
校招火热招聘中
官网直投
第三题我写的python 跟着一样的思路呀 一直超时
1
送花
回复
分享
发布于 2022-09-13 20:48 北京
第一题不用分大小写,不过这次的难度真的太低了
点赞
送花
回复
分享
发布于 2022-09-13 20:45 北京
https://www.luogu.com.cn/paste/9gxt1dju大佬能看看我第三题有啥问题吗,我感觉和你一样啊。。
点赞
送花
回复
分享
发布于 2022-09-13 21:01 广东
最后一题不是标准的A*寻路算法吗,怎么会有人说简单呢
点赞
送花
回复
分享
发布于 2022-09-13 21:06 浙江
二三题目是什么
点赞
送花
回复
分享
发布于 2022-09-13 20:45 北京
大佬这三题都AC了吗?
点赞
送花
回复
分享
发布于 2022-09-13 21:10 福建
 success蚌埠住了,没用到呀
点赞
送花
回复
分享
发布于 2022-09-13 22:18 湖南

相关推荐

10 19 评论
分享
牛客网
牛客企业服务