现在的位置: 首页 > 综合 > 正文

华为机试

2014年06月05日 ⁄ 综合 ⁄ 共 1581字 ⁄ 字号 评论关闭
华为秋招部分机试题:
1.给定的一个字符串,比如:this is my program,要求将每个单词的首字母大写,输出:This Is My Program
2.给定一个字符串,要求将其逆向输出,如:adcdefgik,输出:kigfedcda
3.给定一个字符串,要求删掉重复的字符,只保留其中一个。如:aabcdddffgh,输出:abcdfgh
4.给定一个字符串,让你判定是否是正确的邮件地址

以上是部分秋招的机试题,估计这次也不会变,所有的机试题都是关于字符处理的。工程已经给你建好了,其中有个函数是空的,你需把
该函数填写完整,以实现题目要求的功能即可。

另外,之前参加过华为面试的同学,希望能分享下你的机试题,谢谢。

冒泡:
#include <iostream>
using namespace std;

void BubbleSort(int *a,int n)
{
	int i,j;
	for (i=0; i<n; i++)
		for (j=1; j<n-i; j++)
			if (a[j-1] > a[j])
			{
				int temp = a[j-1];
				a[j-1] = a[j];
				a[j] = temp;
			}
}

int main()
{
	int A[5],i;
	cout << "input 5 numbers: ";
	for (i=0; i<5; i++)
		cin >> A[i];
	cout << "After sorted, the array is: ";
	BubbleSort(A,5);
	for (i=0; i<5; i++)
		cout << A[i] << '\0';
	cout << endl;

	return 0;
}
#include <iostream>
using namespace std;

void Convert(char *str)
{
	str[0] = str[0] - 32;
	for (int i=1; str[i]!='\0'; i++)
	{
		if (str[i-1] == ' ' && str[i] != ' ')
			str[i] = str[i] - 32;
	}
}

int main()
{
	char sentence[80];
	gets(sentence);
	Convert(sentence);
	cout << sentence << endl;
	return 0;
}








#include <iostream>
using namespace std;

void Reverse(char *str)
{
	int len = strlen(str);
	int i,j;
	for (i=0,j=len-1; i<j; i++,j--)
	{
		char temp = str[i];
		str[i] = str[j];
		str[j] = temp;
	}
}

int main()
{
	char sentence[80];
	cin >> sentence;
	Reverse(sentence);
	cout << sentence << endl;
	return 0;
}






#include <iostream>
using namespace std;

void Reverse(char *str)
{
	int len = strlen(str);
	int i,j;
	for (i=0,j=len-1; i<j; i++,j--)
	{
		char temp = str[i];
		str[i] = str[j];
		str[j] = temp;
	}
}

int main()
{
	char sentence[80];
	cin >> sentence;
	Reverse(sentence);
	cout << sentence << endl;
	return 0;
}





#include <iostream>
using namespace std;

void Delete(char *str)
{
	cout << str[0];
	for (int i=1; str[i]!='\0'; i++)
	{
		if (str[i] != str[i-1])
			cout << str[i];
	}
	cout << endl;
}

int main()
{
	char sentence[80];
	gets(sentence);
	Delete(sentence);
	return 0;
}

抱歉!评论已关闭.