当前位置:网站首页>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;
}边栏推荐
- Redis——热点key问题
- CUDA and Direct3D consistency
- CTF web practice competition
- Selenium+msedgedriver+edge browser installation driver pit
- FE - Weex 使用简单封装数据加载插件为全局加载方法
- 2020-9-23 QT的定时器Qtimer类的使用。
- AWD学习
- Learn about various joins in SQL and their differences
- Distributed transactions: the final consistency scheme of reliable messages
- Redis - big key problem
猜你喜欢

Linux MySQL 5.6.51 community generic installation tutorial

PgSQL学习笔记

由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决

js中map和forEach的用法

How to try catch statements that return promise objects in JS

查询GPU时无进程运行,但是显存却被占用了

Linked list (linear structure)

A preliminary study on ant group G6

由于不正常断电导致的unexpected inconsistency;RUN fsck MANUALLY问题已解决

apt命令报证书错误 Certificate verification failed: The certificate is NOT trusted
随机推荐
The intern left a big hole when he ran away and made two online problems, which made me miserable
AtCoder Beginner Contest 253 F - Operations on a Matrix // 树状数组
Fe - use of weex development weex UI components and configuration use
pytest(3)parametrize参数化
Android - Kotlin 下使用 Room 遇到 There are multiple good constructors and Room will ... 问题
FE - Eggjs 结合 Typeorm 出现连接不了数据库
js中正则表达式的使用
Shardingsphere JDBC
[literature reading and thought notes 13] unprocessing images for learned raw denoising
华为MindSpore开源实习机试题
2020-9-23 QT的定时器Qtimer类的使用。
Latex 报错 LaTeX Error: The font size command \normalsize is not defined问题解决
Vector types and variables built in CUDA
Warp matrix functions in CUDA
Log (common log framework)
Asynchronous data copy in CUDA
virtualenv和pipenv安装
FE - Weex 使用简单封装数据加载插件为全局加载方法
unittest. Texttestrunner does not generate TXT test reports
蚂蚁集团g6初探