比特大陆 算法

一面

2021-10-8

项目

代码

矩阵乘法

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int compute_matrix(const vector<vector<int>>& mat1, const vector<vector<int>>& mat2, vector<vector<int>>& res ){
    int m1 = mat1.size();
    int n1  = mat1[0].size();
    int m2 = mat2.size();
    int n2 = mat2[0].size();
    if(n1!=m2){
        return -1;
    }
    res.clear();
    for(int i = 0; i<m1; i++){
        res.push_back(vector<int>(n2, 0));
    }

    for(int i = 0; i<m1; i++){
        for(int j = 0; j<n2; j++){
            for(int k =0; k<m2; k++){
                res[i][j]+=mat1[i][k]+mat2[k][j];            
            }
        }
    }

    return 1;

}

int main() {
    //int a;
    //cin >> a;
    vector<vector<int>> mat1 = {{1,1},
                                {1,1}};
    vector<vector<int>> mat2 = {{2,2}, 
                                {2,2}};
    vector<vector<int>> res;
    auto f = compute_matrix(mat1, mat2, res);
    for(const auto& line:res){
        for_each(line.begin(), line.end(), [](int a){cout << a << " ";});
        cout << endl;
    }
    cout << "Hello World!" << endl;
}

C++基础

1、static关键字
对普通函数声明static关键字,只能当前文件内部使用,对外隐藏

静态全局变量(或者函数)在声明它的整个文件都是可见的,而在文件之外是不可见的; 

2、拷贝构造

#比特大陆##笔经#
全部评论
楼主1面多长时间?
点赞 回复
分享
发布于 2021-10-08 14:01
楼主通过了没 有消息吗
点赞 回复
分享
发布于 2021-10-08 21:01
秋招专场
校招火热招聘中
官网直投
一面写代码吗
点赞 回复
分享
发布于 2021-10-22 15:41

相关推荐

1 6 评论
分享
牛客网
牛客企业服务