2014华为校招机试题目总结

1.手机电池余量
描述: 自从有了智能手机,时刻都要关心手机的电量。你的任务很简单,用程序打印符号来表示当前手机的电量。
用10行和10列来表示电池的电量,同时在外围加上边框,每一行表示10%的电量。
假设还有50%的电量,则显示如下:

+----------+
|----------|
|----------|
|----------|
|----------|
|----------|
|++++++++++|
|++++++++++|
|++++++++++|
|++++++++++|
|++++++++++|
+----------+
运行时间限制: 无限制 
内存限制:无限制 
输入: 多组测试数据,第一行为测试数据组数N(N<10),紧接着是N行,每行一个数,表示电量,这个数值可能是0,10,20 ,30,40,50,60,70,80,90,100

输出: 每组数据输出一个电池的电量,每组数据之间用15个“=”隔开。

Sample Input

2
50
0
Sample Output
+----------+
|----------|
|----------|
|----------|
|----------|
|----------|
|++++++++++|
|++++++++++|
|++++++++++|
|++++++++++|
|++++++++++|
+----------+
===============
+----------+
|----------|
|----------|
|----------|
|----------|
|----------|
|----------|
|----------|
|----------|
|----------|
|----------|
+----------+
===============

#include <iostream>
#include <string>
using namespace std;
void print(int N, int *num)
{
	if(N < 0 || num == NULL)
		return;
	string str1 = "+----------+";
	string str2 = "|----------|";
	string str3 = "|++++++++++|";
	string str4 = "===============";
	for(int i = 0; i < N; i ++)
	{
		int temp = num[i] / 10;
		cout << str1 << endl;
		for(int j = 0; j < 10 - temp; j ++)
			cout << str2 << endl;
		for(int k = 0; k < temp; k ++)
			cout << str3 << endl;
		cout << str1 << endl;
		cout << str4 << endl;
	}
}

int main()
{
	int N;
	cin >> N;
	int a[10];
	for(int i = 0; i < N; i ++)
		cin >> a[i];
	print(N, a);
	return 0;
}
2. 姓名的夫妻相

在中国,形容夫妻恩爱的词汇中,大家用的比较多的就是夫妻相。所谓夫妻相,就是两个人看上去比较般配,长相、身材等某些方面有一定的相似度。本题则另辟蹊径,从人的姓名维度,以字母重复个数来寻找最具夫妻相的人。
题目中预先给定一组女士的姓名拼音。输入男士的姓名拼音(拼音中间可以有空格,字母全部小写),依预先给定姓名拼音的先后遍历所有姓名,输出字母重复数最多的女士姓名。
规则1:如果字母重复数最多的女士有多位相同,则以最先匹配的女士做为最具夫妻相的人选。
规则2:人名中的相同字母,按重复一次处理。例如:li ling li lei 重复的字符个数为2,而不是4
预置女士名单(先后循序必须保证):
"wang fei",
"zhang man yu",
"zhang zhi yi",
"li li",
"li xiao man",
"li yu cun",
"yang ni",
"xiao tong",
"li lei",
"zhang san"
运行时间限制无限制 
内存限制无限制 
输入输入一个男士姓名,字符串 
输出输出最具夫妻相的女士姓名

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 10
char *womanName[N]={"wang fei",
"zhang man yu",
"zhang zhi yi",
"li li",
"li xiao man",
"li yu cun",
"yang ni",
"xiao tong",
"li lei",
"zhang san"
};

void findMatch(char *woman[], char *man, char *output)
{
	int i;
	int count =0 ;
	int max = 0;
	int status = 0;

	for (i = 0 ; i < N; i++)
	{
		char *s = man;
		while(*s)
		{
			char *p = woman[i];
			while (*p)
			{
				if (*s == *p)
				{
					if (*s != ' ')
					{
						count++;
					}				
				}
				p++;			
			}
			s++;
		}
		if (count > max)
		{
			max = count;
			status = i;
		}
		count = 0;
	}
	strcpy(output, woman[status]);

}

int main()
{
	char manName[20];
	char match[20] = "";
	gets(manName);
	findMatch(womanName, manName, match);
	printf("%s\n", match);
	return 0;
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值