当前位置:网站首页>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;
}
边栏推荐
- VSCODE 安装LATEX环境,参数配置,常见问题解决
- Detailed definition of tensorrt data format
- No process runs when querying GPU, but the video memory is occupied
- [literature reading and thought notes 13] unprocessing images for learned raw denoising
- Automation - when Jenkins pipline executes the nodejs command, it prompts node: command not found
- CTF three count
- Redis - big key problem
- web自动化切换窗口时报错“list“ object is not callable
- 部署api_automation_test过程中遇到的问题
- Latex在VSCODE中编译中文,使用中文路径问题解决
猜你喜欢
Code skills - Controller Parameter annotation @requestparam
Latex compilation error I found no \bibstyle &\bibdata &\citation command
pytest(2) mark功能
Redis——热点key问题
Win10: add or delete boot items, and add user-defined boot files to boot items
The intern left a big hole when he ran away and made two online problems, which made me miserable
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)
Sublime Text 配置php编译环境
ctf-web之练习赛
Uploading attachments using Win32 in Web Automation
随机推荐
Vscode installation, latex environment, parameter configuration, common problem solving
js中正则表达式的使用
CTF web practice competition
ModuleNotFoundError: No module named ‘jieba. analyse‘; ‘ jieba‘ is not a package
JS modification element attribute flipping commonly used in selenium's Web Automation
压力测试修改解决方案
Sentinel Alibaba open source traffic protection component
Vector types and variables built in CUDA
selenium+msedgedriver+edge浏览器安装驱动的坑
Win10桌面图标没有办法拖动(可以选中可以打开可以删除新建等操作但是不能拖动)
Pytest (1) case collection rules
Fe - use of weex development weex UI components and configuration use
Browser scrolling for more implementations
Warp shuffle in CUDA
奇葩pip install
Latex 编译报错 I found no \bibstyle & \bibdata & \citation command
华为MindSpore开源实习机试题
Deployment API_ automation_ Problems encountered during test
After reading useful blogs
Fe - wechat applet - Bluetooth ble development research and use