最近几年HUAWEI的利润日胜一日,所以雇员价格也是水涨船高。本次网上编程时间是2017年3月17日晚上7点,共3个小编程题
题目一太简单了~~,就是把控制台输入的字符串小写转大写,忽略非字母字符。
题目二:集福卡,输入是01011 这样的字符串,代表爱国、敬业、富强、等福卡是否集齐。题目要求是有小于10人的组,求组内的人总共集齐了多少五福。
这就很简单了,不就是累加统计吗~~
// HUAWEI_job.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char ch;
int count[5] = {0};
int count_times = 0;
while((ch = getchar()) != EOF)
{
if(count_times < 5)
{
if(ch == '1')count[count_times++]++;
else count_times++;
}
else count_times = 0;
}
int min = count[0];
for(int i=0;i<5;++i)
{
if(count[i] < min)min = count[i];
//cout<<count[i]<<" " ;
}
cout<<min;
return 0;
}
反思,做这个题其实浪费很多时间,从中可以看出自己对字符串的操作及其不熟练,在以后的面试中需要重视字符和字符串的输入输出及操作。
while((ch = getchar()) != EOF)的作用是读取除了EOF之外(控制台里,EOF用Ctrl+Z输入)所有字符内容。
题目三:设计后序表达的简单控制台输入计算器,输入数字是16位的,幸运的是16位单位数,所有不用考虑多位数字的转换。A代表10,B代表11,,,F代表15。运算符只有+,-,*三种。因此引入堆栈,遇到数字转换成int压入,遇到运算符弹出两个进行运算。考官是把复杂题目设计简单了,我觉得这种后序,前序,中序等计算器挺热门的,考点综合,大家都喜欢~~,能难能易~~
// HuaWei_postExPress.cpp : 定义控制台应用程序的入口点。
//
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main()
{
string exp;
getline(cin,exp);
stack<int> opnd;
int i=0;
char ch;
while(i < exp.length())
{
ch = exp[i++];
if(ch == '+')
{
int num2 = opnd.top();
opnd.pop();
int num1 = opnd.top();
opnd.pop();
//compute result;
int ret = num1 + num2;
opnd.push(ret);
}
else if(ch == '-')
{
int num2 = opnd.top();
opnd.pop();
int num1 = opnd.top();
opnd.pop();
//compute result;
int ret = num1 - num2;
opnd.push(ret);
}
else if(ch == '*')
{
int num2 = opnd.top();
opnd.pop();
int num1 = opnd.top();
opnd.pop();
//compute result;
int ret = num1 * num2;
opnd.push(ret);
}
else if(ch >= '0' && ch <= '9')
{
//compute result;
int ret = ch - '0';
opnd.push(ret);
}
else if(ch == 'A')
{
//compute result;
int ret = 10;
opnd.push(ret);
}
else if(ch == 'B')
{
//compute result;
int ret = 11;
opnd.push(ret);
}
else if(ch == 'C')
{
//compute result;
int ret = 12;
opnd.push(ret);
}
else if(ch == 'D')
{
//compute result;
int ret = 13;
opnd.push(ret);
}
else if(ch == 'E')
{
//compute result;
int ret = 14;
opnd.push(ret);
}
else if(ch == 'F')
{
//compute result;
int ret = 15;
opnd.push(ret);
}
}
cout<<opnd.top();
return 0;
}
反思,cin>>string 无法应对一行的空格,所以需要用getline(cin, string)来得到完整的一行到string里去。
总结:多参编程,多实践,重视字符串。