2014年多益网络春季校园招聘机试题

总共三道题,共两个小时的时间,题目分别是:

1.输入整型字符串,输出该整数;如:输入“345”,输出345;

参考:

#include<iostream>
#include"string"
using namespace std;

int exp(int n)
{
	int num = 1;
	while(n > 0)
	{
		num = num * 10;
	}
	return num;
}
void main()
{
	string str = 0;
	while(cin>>str)
	{
		int num = 0;
		int len = str.length();
		for(int i = 0; i < len; i++)
		{
			num = num + (str[i] - 48) * exp(len - i - 1);
		}
		cout<<num<<endl;
	}
}


2.输入一个字符串,输出该字符串的最长连续子串;如:输入“abcd12345abcdefg”,则输出abcdefg;

参考:

#include<iostream>
#include"string"
using namespace std;

void main()
{
	string str = 0;
	while(cin>>str)
	{
		int maxlen = 0;//最长子串长度
		int currentlen = 0;//当前子串长度
		int start = 0;//最长子串开始下标
		int len = str.length();
		for(int i = 0; i < len; i++)
		{
			start = i;
			while(str[i] == str[i+1] - 1)
			{
				currentlen++;
				i++;
			}
			currentlen++;
			if(currentlen > maxlen)
			{
				maxlen = currentlen;
			}
		}
		for(i = start; i < maxlen; i++)
			cout<<str[i];
		cout<<endl;
	}
}

3.输入一个整型数组,输出该数组的主要元素,如果不存在主要元素,则输出-1,找出好的算法,需要考虑时间和控件复杂度;(数组的主要元素:数组中该元素出现的次数超过总数组的一半);如:数组A={1,2,3,4,5,5,5,6,5,5,5,5,5},则输出5.

参考:(排序法,最简单)

#include<iostream>
using namespace std;
void main()
{
	int n = 0;
	while(1)
	{
		cout<<"input the size of the array:";
	cin>>n;
	int *arr = new int[n];
	cout<<"input the element of the array:"<<endl;
	for(int i = 0; i < n; i++)
	{
		cin>>arr[i];
	}
	for(i = 0; i < n; i++)
	{
		for(int j = 0; j < n - i - 1; j++)
		{
			if(arr[j] > arr[j + 1])
			{
				int tem = arr[j];
				arr[j] = arr[j + 1];
				arr[j+1] = tem;
			}
		}
	}
	if(arr[n/2] == arr[n/2 + 1])
	{
		int mainelement = arr[n/2];
		int i = 0;
		while(arr[i] != mainelement)
		{
			i++;
		}
		int start = i;
		if(arr[start + n/2] == mainelement)
			cout<<mainelement<<endl;
		else
			cout<<-1<<endl;

	}
	else
		cout<<-1<<endl;
	}
}
都是很简单的题目,留给师弟师妹准备多益的机试。关于多益的机试,有一些要求算法的,千万别想太久,最关键的还是要做出来,几乎可以说做出来了都可以进面试了的,祝师弟师妹成功。


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值