牛客网华为机考试题(1)

(1)题目:计算字符串最后一个单词的长度,单词以空格隔开。

​
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;


int main()
{
	int num = 0;
	string str = "";
	getline(cin, str);

	for (auto charA : str)
	{
		if (charA != ' ')
		{
			num += 1;
		}
		else {
			num = 0;

		}
	}
	cout << "字符的个数为:" << num << endl;
	system("pause");
    return num;
}

​

(2)题目:写出一个程序,接受一个由字母和数字组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写。

// nowcode2.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

int main()
{
	cout << "请输入字符串" << endl;
	string str;
	char charA;
	char charC;
	int num = 0;

	cout << "请输入字符串,结束输入请按Y" << endl;
	while (cin >> charA) {
		if (charA == 'Y')
			break;
		str += charA;
	}
	
	cout << "请输入您想统计的字符" << endl;
	cin >> charC;

	for (auto charB : str)
	{
		if (charB == charC)
			num += 1;

	}
	cout << "统计的结果为" << num << endl;
	system("pause");
    return 0;
}

(3)题目:明明想在学校中请一些同学一起做一项问卷调查,为了试验的客观性,他先用计算机生成了N个1到1000之间的随机整数(N<=1000),对于其中重复的数字,只保留一个,把其余相同的数去掉,不同的数对应着不同的学生的学号。然后再把这些数从小到大排序,按照排好的顺序去找同学做调查。请你协助明明完成“去重”与“排序”的工作(同一个测试用例可能会有多组数据,希望大家能正确处理)

Input Param

n   输入随机数的个数

inputArray   n个随机数组成的数组

 

Return Value

OutputArray   输出处理后的随机整数

注:测试用例保证输入参数的正确性,答题者无需验证,测试用例不止一组。

// nowcode3.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
	int N, n;
	while (cin >> N) {
		int a[1001] = { 0 };
		while (N--)
		{
			cin >> n;
			a[n] = 1;

		}
		for (int i = 0; i < 1001; i++)
		{
			if (a[i])
				cout << i << endl;
		}
	}



	system("pause");
	return 0;
}

(4)连续输入字符串,请按长度为8拆分每个字符串后输出到新的字符串数组;

长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。

// nowcode4.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string tempStr;
	char tempChar;
	string strArray[100], strAaary2[100];
	int num = 0;
	while (cin >> tempChar) {
		if (tempChar != ' ')
		{
			tempStr = "" + tempChar;
		}
		else
		{
			strArray[num] = tempStr;
			num += 1;
		}
	}

	int resultNum = 0;
	int tempStr2;
	for (int i = 0; i <= num; i++)
	{
		int a = strArray[i].length();
		string str = strArray[i];
		int tempNum = int(a / 8) + 8;
		for (int j = 0; j < tempNum; j++)
		{
			if (((j+1) % 9 ) != 0 )
			{
				string tempStr2 = string("") + str[j];
			}
			else
			{
				strAaary2[resultNum] = tempStr2;
				resultNum += 1;
			}		
		}
	}

    return 0;
}

(5)写出一个程序,接收一个十六进制的输,输出该数值的十进制表示。(多组同时输入)

// nowcode5.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int Atoi(string s, int radix)    //s是给定的radix进制字符串
{
	int ans = 0;
	for (int i = 0; i<s.size(); i++)
	{
		char t = s[i];
		if (t >= '0'&&t <= '9') ans = ans*radix + t - '0';
		else ans = ans*radix + t - 'a' + 10;
	}
	return ans;
}

int trans(char c)
{
	if(c > 47 && c < 58)
		return c - 48;
	if(c > 64 && c < 71)
		return c - 55;
	if (c > 96 && c < 103)
		return c - 87;

}

int sixteen(int n)
{
	int tempRes = 1;
	for (int i = 0; i < n; i++)
	{
		tempRes = tempRes * 16;
	}
	return tempRes;
}

int main()
{
	string tempStr;
	
	vector<string> vecStr;
	
	while (cin >> tempStr)
	{
		vecStr.push_back(tempStr);
	}

	for (int i = 0; i < vecStr.size(); i++)
	{
		string str = vecStr[i];
		int result = 0;
		int tempNum = str.size();
		for (int i = 0; i < tempNum; i++)
		{
			
			/*cout << trans(str[i]) << endl;
			cout << sixteen(tempNum - i - 1) << endl;*/
			result = trans(str[i])*sixteen(tempNum - i - 1) + result;

		}
		cout << result <<"   "<< endl;

	}
	

	//cout << result << endl;
	system("pause");
    return 0;
}

 

int Atoi(string s, int radix)    //s是给定的radix进制字符串
{
	int ans = 0;
	for (int i = 0; i < s.size(); i++)
	{
		char t = s[i];
		if (t >= '0'&&t <= '9') ans = ans*radix + t - '0';
		else ans = ans*radix + t - 'a' + 10;
	}
	return ans;

}

(6)功能:输入一个正整数,按照从小到大的顺序输出它的所有质数的因子(如180的质数因子为2 2 3 3 5 )最有一个数后面也要有空格

详细描述:函数接口说明:public String getResult(long ulDataInput)

输入参数:long ulDataInput:输入的正整数

返回值:string

// nowcode6.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>

using namespace std;

vector<int> vec;

//判断质数因子,并加入容器中
int prime(int n)
{
	//质数标记变量
	int sign = 0;
	//判断是否为质数
	for (int i = 2; i <= n; i++)
	{
		if (n % i == 0)
			if (i == n)
			{
				sign = 1;
				break;
			}
			else
			{
				sign = 0;
				break;
			}
				
	}


	if (sign)
	{	
		vec.push_back(n);
		return n;
	}
	else
	{
		//若不是质数,求出第一个质数因子,加入容器,利用迭代的方法继续计算
		for (int i = 2; i < n; i++)
		{
			if (n % i == 0)
			{
				vec.push_back(i);
				return(prime(n / i));
			}
				
		}
	}

	
}

int main()
{
	int tempNum;
	cin >> tempNum;
	int n = prime(tempNum);
	
	for (int i = 0; i < vec.size(); i++)
	{
		cout << vec[i] << endl;
	}
	system("pause");
    return 0;
}

(7)写出一个程序,接收一个正浮点数值,输出该数值的近似正整数。如果小数点后数值大于5,向上取整;小于5,则向下取整。

// nowcode7.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;


int main()
{
	float numF;
	int result;
	cin >> numF;

	float aa = numF - int(numF);
	float temp = (numF - int(numF)) * 10;
	if (temp >= 5)
		result = int(numF + 1);
	else
		result = int(numF);

	cout << result << endl;
	system("pause");
    return 0;
}

(8)数据表记录包含表索引和数值(int范围的整数),请对表索引相同的记录进行合并即将相同索引的数值进行求和运算,输出按照key值升序进行输出。

// nowcoude8.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main()
{
	string strKey;
	int value;
	int n;
	map<string, int> tempMap;

	while (cin>>n) {
		
		while (n--) {
			cin >> strKey >> value;
			if (!tempMap[strKey])
				tempMap[strKey] = value;
			else
				tempMap[strKey] += value;
		}


		cout << '\n' << endl;
		for (map<string, int>::iterator it = tempMap.begin(); it != tempMap.end(); it++)
		{
			cout << it->first << "  " << it->second << endl;
		}

	}

	
	system("pause");
    return 0;
}

(9)输入一个int型整数,按照从右向左的顺序阅读,返回一个不含重复数字的新的整数。

 

(10)编写一个函数,计算字符串中含有的不同字符的个数。字符在ACSII码范围内(0~127),换行表示结束符,不算在字符里。不在范围内的不作统计。

(11)输入一个整数,将这个整数以字符串的形式逆序输出,程序不考虑负数的情况,若数字含有0,则逆序形式也含有0,如输入为100,则输出为001

(12)写出一个程序,接受一个字符串,然后输出该字符串反转后的字符串

(13)将一个英文语句以单词为单位逆序排放。例如“i am a boy”,逆序排放后为“boy a am i”,所有单词之间用一个空格隔开,语句中除了英文字母外,不再包含其他字符。

(14)给定n个字符串,请对n个字符串按照字典序排列。

(15)输入一个int型的正整数,计算出该int型数据在内存中存储时1的个数。

(16)

(17)

(18)

(19)开发一个简单错误记录功能小模块,能够记录出错的代码所在的文件名称和行号。

处理:1、记录最多8条错误记录,循环记录,对相同的错误记录(净文件名称和行号匹配)只记录一条,错误计数累加;2、超过16个字符的文件名称,只记录文件的最后有效16个字符;3、输入的文件可能带路径,记录文件名称不能带路径。

(20)密码要求:1.长度超过8位2.包括大小写字母数字和其他符号,以上四种至少三种3.不能有相同长度超2的子串重复

(21)密码:假设小明原来一个BBS

 

(85)动态(DP)规划思想

// nowcode85.cpp : 定义控制台应用程序的入口点。
//

//本题等价于求最长公共字串
#include "stdafx.h"
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	string s;
	while (cin >> s) {
		string t(s);
		reverse(t.begin(), t.end());
		int len = t.size();
		vector<int> ans(len + 1, 0);
		vector<vector<int> > dp(len + 1, ans);
		int maxLen = 0;
		for (int i = 1; i <= len; i++) {
			for (int j = 1; j <= len; j++) {
				//cout << i << s[i - 1] << j << t[j - 1] << endl;
				if (s[i - 1] == t[j - 1]) {
					dp[i][j] = dp[i - 1][j - 1] + 1;
					//cout << dp[i][j] << endl;
				}
				if (dp[i][j]>maxLen)
					maxLen = dp[i][j];
			}
		}
		cout << maxLen << endl;
	}
	return 0;
}

(91)请编写一个函数(允许增加子函数),计算n*m的棋盘格子(n为横向的格子数,m为竖向的格子数)沿着各自边缘线从左上角走到右下角,总共有多少种走法,要求不能有回头路,即:只能往右和往下走,不能往左和往上走。

迭代思想

// nowcode93.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

int fun(int m, int n)
{
	if (m == 0 || n == 0)
		return 1;
	return (fun(m - 1, n) + fun(m, n - 1));
}
int main()
{
	int m, n;
	cin >> m >> n;
	int result = fun(m, n);
	cout << result << endl;
	system("pause");
	return 0;
}

(93)编写一个函数,传入一个int型数组,返回该数组能否分成两组,使得两组中各元素加起来的和相等,并且,所有5的倍数必须放在其中一个数组,所有3的倍数在另一个数组中(不包括5的倍数),能满足以上条件,返回true,不满足时返回false。

(99)自守数是指一个数的平方的尾数等于该数自身的自然数,例如:25^2=625,76^2=5776,9376^2=87909376。请求出n以内的自守数的个数。

// nowcoude99.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

//将int类型的值转化为string类型


//判断是否是自守数
bool selfDenfense(int n)
{
	string s = to_string(n);
	string str = to_string(n*n);
	string s1 = str.substr(str.size() - s.size(), str.size());
	if (s == s1)
		return true;
	else
		return false;
}

int main()
{
	int n, num = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		if (selfDenfense(i)) {
			cout << i << endl;
			num += 1;
		}			
	}

	cout << num << endl;
	system("pause");
    return 0;
}

(102)如果统计的个数相同,则按照ASCII码由小大大排序输出。如果有其他字符,则对这些字符不用进行统计。

实现以下接口:输入一个字符串,对字符串中的英文字符,数字,空格进行统计(可反复调用)。按照统计个数由多到少输出统计结果,如果统计的个数相同,则按照ASCII码由小到大排序输出。清空目前的统计结果,重新统计

// nowcode102.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	string str;
	int a = ' ';
	while (cin >> str) {
		int arr[122] = { 0 };
		for (size_t i = 0; i < str.size(); i++) {
			int n = str[i];
			arr[n] += 1;
		}

		//求次数最多的次数是几次
		int maxNum = 0;
		for (int i = 0; i < 122; i++) {
			if (arr[i] > maxNum)
				maxNum = arr[i];
		}

		vector<char> vecChar;
		for (int i = maxNum; i > 0; i--) {
			cout << i << " ";
			vecChar.clear();
			for (int j = 0; j < 122; j++) {
				if (arr[j] == i) {
					char c = j;
					vecChar.push_back(c);
				}
			}
			sort(vecChar.begin(), vecChar.end());

			for (size_t i = 0; i < vecChar.size(); i++)
				cout << vecChar[i];
		}
	}
	system("pause");
    return 0;
}

(103)Redraiment是走梅花桩的高手。Redraiment总是起点不限,从前到后,往高的桩子走,但走的步数最多,不知道为什么?你能提Redraiment研究他最多走的步数吗?

样例输入:6,2 5 1 5 4 5 样例输出 3

提示:6个点的高度各为2 5 1 5 4 5,如从第一个格子开始走,最多为3步,2 4 5;如从第2格开始走,最多为1步 5;如从第3格开始走最多走3步1 4 5...所以这个结果是3.

// nowcode103.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	vector<int> nums;
	while (cin >> n) {
		nums.clear();
		for (int i = 0; i < n; i++) {
			int x;
			cin >> x;
			nums.push_back(x);
		}
		break;
	}

	vector<int> dp(n + 1, 1);
	vector<int> sequence;
	vector<int> res;
	int maxLength = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j < i; ++j) {
			if (nums[i - 1] > nums[j - 1] && dp[j] + 1 > dp[i]) {
				dp[i] = dp[j] + 1;
				maxLength = std::max(maxLength, dp[i]);			
			}
		}
	}
	cout << maxLength << endl;
	system("pause");
    return 0;
}

(104)连续输入字符串(输出次数为N,字符串长度小于100),请按长度为8拆分每个字符串后输出到新的字符串数组,长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。首先输入一个整数,为要输入的字符串个数。

例如:输入:2   abc   123456789   输出:abc00000 12345678 90000000

// nowcode104.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
	int n = 0;
	string tempStr;
	vector<string> vec, res;

	cin >> n;
	while (cin >> tempStr) {

		vec.push_back(tempStr);
		n--;
		if (n == 0) {
			break;
		}
	}

	for (size_t i = 0; i < vec.size(); i++) {
		string str = vec[i];
		string str2 = str;
		int n = str.size() % 8;
		int num = 0;
		if (n == 0) {
			num = str.size();
			
		}	
		else {
			num = (str.size() / 8)*8 + 8;
 			for (size_t i = str.size(); i < num; i++) {
				str2 += '0';
			}
		}
		for (size_t i = 0; i < str2.size(); i += 8) {
			string s = str2.substr(i, i + 8);
			res.push_back(s);
		}
	}
	
	for (size_t i = 0; i < res.size(); i++) {
		cout << res[i] << endl;
	}
	system("pause");
    return 0;
}

(107)计算一个数字的立方根,不使用库函数。详细说明:输入double,待求解参数。 返回值:double 输入参数的立方根,保留一位小数

// nowcode107.cpp : 定义控制台应用程序的入口点。
//

//求一个double类型的立方根,返回double
#include "stdafx.h"
#include <iostream>
#include <iomanip>

using namespace std;

double newton(double a)
{
	double x = 1;
	while (((x*x*x - a) >= 1e-7) || (a - x*x*x) >= 1e-7)
	{
		x = (x - x / 3 + a / (3 * x*x));
	}
	return x;
}

int main()
{
	double num;
	while (cin >> num) {
		cout <<setprecision(1)<<fixed<< newton(num) << endl;
	}
	system("pause");
    return 0;
}

(108)正整数A和正整数B的最小公倍数是指能被A和B正处的最小正整数,设计一个算法,求输入A和B的最小公倍数。

// nowcoude108.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
	int a = 0, b = 0, c = 0, result;
	bool sign = false;
	
	cin >> a >> b;
	c = a > b ? a : b;
	while (!sign) {
		if (c % a == 0 && c % b == 0)
		{
			sign = true;
			break;
		}
		else
			c += 1;
	}
	
	cout << c << endl;
	system("pause");
	return 0;
}

 

代码纯手打,本人能力有限,如若不合理之处,请各位大佬多多指教...

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
华为销售类数字能源bd机考试题通常涵盖以下内容: 一、数字能源基础知识:考查对数字能源概念、发展趋势、应用场景等方面的理解。需要了解数字能源的特点、优势以及在不同行业中的应用。 二、华为数字能源产品知识:考查对华为数字能源产品的了解程度。要掌握华为数字能源产品的特点、功能、使用方法以及与竞品的比较等方面的知识。 三、数字能源销售技巧和方法:考查对数字能源销售过程中关键环节的掌握,如需求分析、解决方案设计、演示表达、谈判技巧等。 四、数字能源市场分析:考查对数字能源市场现状、竞争对手、市场趋势等方面的了解和分析能力。需要具备市场调研、竞争分析、市场定位等能力。 五、案例分析和解决方案设计:考查对实际案例的分析和解决问题的能力。需要从客户需求出发,结合华为数字能源产品特点和解决方案,设计出最合适的解决方案。 六、销售计划和业绩达成能力:考查对销售计划制定和实施的能力,包括目标设定、资源调配、销售策略制定等。 七、团队协作和沟通能力:考查对团队合作和沟通协作能力的理解和实践。需要具备良好的团队协作和沟通能力,与团队成员密切合作并达成共同目标。 综上所述,华为销售类数字能源bd机考试题主要考查对数字能源基础知识、华为产品知识、销售技巧方法、市场分析能力、案例分析和解决方案设计、销售计划和业绩达成能力以及团队协作和沟通能力的掌握程度。准备考试时,需深入了解以上内容并提前进行充分准备。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值