9.4 荣耀笔试,媒体算法,讨论帖

侵删
侵删
侵删

感谢cxy同学陪伴🤤🤤🤤


请大家评论区讨论~

第一题

切数字重组,递归就行了
题目不难,就是输入太费劲了,流下了菜鸡的泪水。。。
void test1(vector<vector<int>> arr, vector<int>& p_arr,  vector<vector<int>>& out, int n){
    for(int i = 0; i<arr.size(); i++){
        vector<int> tmp;
        int& cur_p = p_arr[i];          // 每一行的指针
        int cur_len = arr[i].size();

        if(cur_p>=cur_len){
            continue;
        }
        
        if(cur_p+n < cur_len){
            tmp.assign(arr[i].begin()+cur_p, arr[i].begin()+cur_p+n);
            cur_p += n; 
        }

        else{
            tmp.assign(arr[i].begin()+cur_p, arr[i].end());
            cur_p+=n;
        }
        
        out.push_back(tmp);

    }
    bool flag = true;
    for(int i = 0; i<p_arr.size(); i++){
        if(p_arr[i]<arr[i].size()){
            flag = false;
        }
    }
    if(flag){
        return;
    }
    test1(arr, p_arr, out, n);
}

int main(){
    int n = 0;
    cin >> n;
    vector<vector<int>> arr;

    string str_in;
    while(cin >> str_in){
        vector<int> data;
        string tmp;
        std::stringstream input(str_in);
        while(getline(input, tmp, ',')){
            // data.push_back(tmp);
            if(tmp!=","){
                data.push_back(atoi(tmp.c_str()));
            }    
        }
        // debug
        // for(const auto& ele:data){
        //     cout << ele << " ";
        // }
        // cout << endl;
        arr.push_back(data);
        
    }


    // int n = 3;
    // vector<vector<int>> arr = {
    //                             {2,5,6,7,9,5,7},
    //                             {1,7,4,3,4}

    // };
    vector<int> p_arr(arr.size(), 0);
    vector<vector<int>> out;
    test1(arr, p_arr, out, n);      // out 是输出

    vector<int> out_arr;
    for(const auto& ele:out){
        for(const auto& e:ele){
            // cout << e << ", ";
            out_arr.push_back(e);
        }
        // cout << endl;
    }

    // cout << "res :" << endl;
    int i = 0;
    for(const auto& ele: out_arr){
        if(i==out_arr.size()-1){
            cout << ele << endl;
        }
        else{
            cout << ele << ",";
            i++;
        }
    }
    cout << endl;

    return 0;
    
    return 0;
}




第二题

不会
区间排序?
求大佬评论区指教

第三题

解算括号,感觉是递归,或者dfs

我这个是不对的!!!
string test2_helper(string& str, int start_p, int& end_p){
    // cout << start_p << endl;
    char num_str = str[start_p];
    int num = atoi(&num_str);
    // cout << num << endl;
    string tmp_str;
    char flag = str[start_p+1];
    // cout << flag << endl;
    char end_flag;
    if(flag=='('){
        end_flag = ')';
    }
    if(flag=='{'){
        end_flag = '}';
    }
    if(flag=='['){
        end_flag = ']';
    }
    int i = start_p+2;
    while( i<str.size() && str[i]!=end_flag){
        tmp_str.push_back(str[i]);
        i++;
    }
    end_p = i;
    // cout << "end_p: " <<end_p <<endl;
    // cout << "tmp_str: " << tmp_str << endl;

    string out;
    for(int i = 0; i<num; i++){
        // cout << "i: " << i << endl;
        out+=tmp_str;
        // cout << tm
    }

    // cout << "tmp_str: " << tmp_str << endl;

    return out;

}

string test2(string& str){
    string res;
    for(int i = 0; i<str.size(); ){
        if(str[i]>='0' && str[i] <='9'){
            int end_p = 0;
            auto tmp_str = test2_helper(str, i, end_p);
            // cout << "tmp_str: " << tmp_str << endl;
            res+=tmp_str;
            i = end_p+1;
        }
        else{
            res+=str[i];
            i++;
        }
    }
    return res;
}



#荣耀笔试##笔经##荣耀手机#
全部评论
有评测了吗 我跟你一样
点赞 回复
分享
发布于 2021-09-09 09:48
请问笔试用什么编程语言有要求吗
点赞 回复
分享
发布于 2021-09-10 17:01
博乐游戏
校招火热招聘中
官网直投
媒体算法和计算机视觉算法的题会类似嘛
点赞 回复
分享
发布于 2021-09-23 20:03
楼主受到offer了码
点赞 回复
分享
发布于 2021-10-22 13:18
楼主开了多少?我媒体算法,进了池子
点赞 回复
分享
发布于 2021-11-17 03:26
您好请问笔试时间是两个小时吗
点赞 回复
分享
发布于 2022-09-02 16:36 浙江

相关推荐

头像
不愿透露姓名的神秘牛友
03-13 14:57
点赞 评论 收藏
转发
2 9 评论
分享
牛客网
牛客企业服务