当前位置:网站首页>Huawei mindspire open source internship machine test questions
Huawei mindspire open source internship machine test questions
2022-07-02 06:43:00 【Sand is sand】
Record Huawei MindSpore Open source internship machine test topic , Three questions .
On the whole, it's not too difficult . The difficulty is that the input and output are awkward , I don't know whether it was intentional or for other reasons .
The first question : Please refer to this question The finger of the sword Offer 39. A number that appears more than half the times in an array
There are more than half of the numbers in the array ( Hash )


Answer key :
//
// Created by zhanghao on 2022/6/2.
//
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
using namespace std;
int countNum(vector<int> & nums){
int ans = 0;
int n = nums.size();
unordered_map<int,int> mymap(n);
for(int i = 0 ; i < n; i++){
mymap[nums[i]]++;
}
for(int i = 0 ; i < n;i++){
if(mymap[nums[i]] > n/2){
ans = nums[i];
break;
}
}
return ans;
}
int main(){
vector<int> nums;
int num;
string s;
cin >> s;
for(auto i : s){
if(i >= '0' && i <= '9'){
nums.push_back((i-'0'));
}
}
int ans = countNum(nums);
cout<<ans<<endl;
return 0;
}The second question : Please refer to this question 14. The longest common prefix
Answer key :
//
// Created by zhanghao on 2022/6/2.
//
#include <iostream>
#include <vector>
#include <string>
using namespace std;
string longest(const string& str1, const string& str2) {
int length = min(str1.size(), str2.size());
int index = 0;
while (index < length && str1[index] == str2[index]) {
++index;
}
return str1.substr(0, index);
}
string longestCommonPrefix(vector<string>& strs) {
if (!strs.size()) {
return "";
}
string prefix = strs[0];
int count = strs.size();
for (int i = 1; i < count; ++i) {
prefix = longest(prefix, strs[i]);
if (!prefix.size()) {
break;
}
}
return prefix;
}
int main()
{
// please define the C++ input here. For example: int a,b; cin>>a>>b;;
// please finish the function body here.
// please define the C++ output here. For example:cout<<____<<endl;
string s;
vector<string> arr;
cin >> s;
int n = s.size();
for(int i = 0 ; i < n;i++){
if(s[i] == '"'){
int left = ++i;
int n = 0;
while(s[i]!='"'){
n++;
i++;
}
string temp = s.substr(left,n);
arr.push_back(temp);
}
}
string ans = longestCommonPrefix(arr);
cout<<ans<<endl;
return 0;
}
Third question : Please refer to this question 96. Different binary search trees

Answer key :
#include <iostream>
#include <vector>
using namespace std;
int numTree(int n){
vector<int> dp(n+1);
dp[0] = 1;
for(int i = 1;i <= n;i++){
for(int j = 0; j <= i-1;j++){
dp[i] += dp[j]*dp[(i-1)-j];
}
}
return dp[n];
}
int main(){
int n;
cin >> n;
int ans = numTree(n);
cout<<ans<<endl;
return 0;
}边栏推荐
- web自动中利用win32上传附件
- FE - Weex 使用简单封装数据加载插件为全局加载方法
- Redis - hot key issues
- Warp shuffle in CUDA
- 部署api_automation_test过程中遇到的问题
- Detailed definition of tensorrt data format
- 日志 - 7 - 记录一次丢失文件(A4纸)的重大失误
- Dynamic global memory allocation and operation in CUDA
- 【文献阅读与想法笔记13】 Unprocessing Images for Learned Raw Denoising
- Utilisation de la carte et de foreach dans JS
猜你喜欢

20201002 vs 2019 qt5.14 developed program packaging

Redis——缓存击穿、穿透、雪崩

蚂蚁集团g6初探

Distributed transactions: the final consistency scheme of reliable messages

The win10 network icon disappears, and the network icon turns gray. Open the network and set the flash back to solve the problem

There is no way to drag the win10 desktop icon (you can select it, open it, delete it, create it, etc., but you can't drag it)

Redis - cluster data distribution algorithm & hash slot

Sentry搭建和使用

Linked list (linear structure)

AWD learning
随机推荐
The default Google browser cannot open the link (clicking the hyperlink does not respond)
sprintf_ How to use s
[daily question 1] write a function to judge whether a string is the string after the rotation of another string.
[literature reading and thought notes 13] unprocessing images for learned raw denoising
kali最新更新指南
Fe - eggjs combined with typeorm cannot connect to the database
Asynchronous data copy in CUDA
Selenium memo: selenium\webdriver\remote\remote_ connection. Py:374: resourcewarning: unclosed < XXXX > solution
Flask migrate cannot detect db String() equal length change
js中对于返回Promise对象的语句如何try catch
Tensorrt command line program
table 组件指定列合并行方法
js中map和forEach的用法
压力测试修改解决方案
Storage space modifier in CUDA
Latex compiles Chinese in vscode and solves the problem of using Chinese path
实现strStr() II
计算属性普通函数写法 和 set get 写法
Thread hierarchy in CUDA
Kotlin - 验证时间格式是否是 yyyy-MM-dd HH:mm:ss