链家网2018秋招内推编程题

凭记忆联想,笔试编程题共有三个:

1.求两个数之和。

要求:输入a,b,输出a与b之和;

例如:

输入:

1 2

3 4

5 6

输出:

3

7

11

C++实现:

#include
using namespace std;
int main(){
	int a,b;
	while(cin>>a>>b){
		cout<


2.求第n个最小质数。

要求:输入n,输出第n个最小的质数,最大数不超过10000;

例如:

输入:

10

输出:

29

提示:前十个质数:2,3,5,7,11,13,17,19,23,29;

C++实现:

#include
#include
using namespace std;

int main(){
	int n,res,count=0;
	cin>>n;
	for(int i=2;i<10000;i++){
		int j=2;
		for(j=2;jsqrt(i)){
			count++;
			res=i;
			if(count>=n) break;
		}
	}
	cout<

3.求斐波拉斯数列。

要求:输入n,输出第n个对应的斐波拉斯数;

例如:

输入:

8

输出:

21

C++实现:

#include
#include
using namespace std;
int fabo(int& m){
	vector res;
	res.push_back(1);
	res.push_back(1);
	for(int i=2;i>n;
	cout<


你可能感兴趣的:(Data,Structure,&,Algorithm,C/C++)