笔试


cvte笔试

把一些问题记下来,

1、A *p=new A;

A a=*p;

A *c=new A;

*c=*p

#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;

class A
{
public:
	A(){cout<<" A"<<endl;}
	A(const A &a){cout<<"copy A"<<endl;}
	A operator=( A &a){cout<<"operator="<<endl; return a;}
};
int main(void)
{
	 
	A *b=new A;
	A a=*b;
	A *c=new A;
	*c=*b;
	

    return 0;
}

输出:

 A
copy A
 A
operator=
copy A
Press any key to continue

总结:

(1)当需要构造的时候用=号,那是调用复制构造函数,当时在赋值的时候,用的是重载=号操作符。

(2)特别要注意,当return的时候,会调用复制构造函数。

(3)形参没有用引用的时候,也会调用复制构造函数。


2、strcopy(str,strcat(p1,p2))//str 是char数组 p1=new char[20]; menset(p1,0,20)

#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;

int main(void)
{
	 
char str[40]="hfskfhdskf";
char *p1=new char[20];
char *p2="hello";
memset(p1,0,20);
strcpy(str,strcat(p1,p2));
cout<<str<<"  "<<p1<<"   "<<p2<<endl;	


    return 0;
}
输出:

hello  hello   hello
Press any key to continue

看来只有这个做对了。

3、char *p ,char*p[5] char *p[10][150]

#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;

int main(void)
{

	char s[5]={'a','b'};
	char s0[2][8]={{'a','a','a','a'},{}};
	char *s1="abcddd";
	char *s2[5];
	char *s3[10][15];
	char s6[5]="122";
	cout<<sizeof(s)<<' '<<sizeof(s0)<<' '<<sizeof(s1)<<' '<<sizeof(s2)<<' '<<sizeof(s3)<<' '<<sizeof(s6)<<endl;

    return 0;
}

输出结果:

5 16 4 20 600 5</span>
Press any key to continue

总结:也就是说常量数组,其大小为数组的大小,一个字符对应1字节,而对于指针,一个指针的长度为4指针数组为4*length;

char *a="123";
 int b[5]={1,2,3,4,5};
 cout<<a<<" "<<*a<<" "<<b[1]<<" "<<*b<<" "<<b<<endl;

输出:

123 1 2 1 003FFE80
请按任意键继续. . .

总结:也就是说当输出指针的时候,是会输出指针指向的那块地址的,而数组却不一样,只能用*取值才行,这就是为什么size不一样的区别。

4、hash 地址 个数 函数{}

已解决


5、linux获取进程信息指令

ps


6、子网掩码 c类地址 一个公司,6个子公司  一个子公司有30台主机

7、find 、 grap指令 

8、快排的比较

ok


9、进程、原子操作、

10、树获取节点数

ok


11、ping 主机的一些信息  ping 127.

12、bootloader

13、函数作为形参

14、字符串的查找与替换  cvt替换为cvte 长度为N

15、m条生产线,n个产品,每个产品的时间为T1....Tn,只能在一条生产线上生产完成,求最短完成时间

 

网易笔试(cc语音)

 

1、cpu大端小端的相关的东西

2、lixnux进程查看与调度

3、sql三表联查

4、堆排序的实现

5、transaction 事务几个特性

6、main函数执行之前,还要做什么工作

7、判断浮点型数是否等于0怎么写

最后一题代码:

#include "stdafx.h"
#include<iostream>
#include<string>
#include<vector>
#include<bitset>
using namespace std;
const int R=3;
const int C=3;
const int INF=65535;
struct Node
{
	int up;
	int down;
	int left;
	int right;
	int value;
}data[R][C];
int CountFunc(int i,int j)
{
	int up=0,down=0,left=0,right=0;//记得一定要初始化
	bool flag=0;
	if(data[i][j].up!=INF&&(data[i][j].value>data[i-1][j].value))
	{
		flag=1;
		up+=CountFunc(i-1,j)+1;
	}
	if(data[i][j].down!=INF&&(data[i][j].value>data[i+1][j].value))
	{
		flag=1;
		down+=CountFunc(i+1,j)+1;
	}
	if(data[i][j].left!=INF&&(data[i][j].value>data[i][j-1].value))
	{
		flag=1;
		left+=CountFunc(i,j-1)+1;
	}
	if(data[i][j].right!=INF&&(data[i][j].value>data[i][j+1].value))
	{
		flag=1;
		right+=CountFunc(i,j+1)+1;
	}
	if(flag)
		return max(max(up,down),max(left,right));
	else
		return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{	
	for(int i=0;i<R;i++)		
	{
		for(int j=0;j<C;j++)
		{
			cin>>data[i][j].value;
			if(i==0)data[i][j].up=INF;
			if(i==R-1)data[i][j].down=INF;
			if(j==0)data[i][j].left=INF;
			if(j==C-1)data[i][j].right=INF;
		}
		
	}
	cout<<data[R-1][C-1].value<<endl;
	int max_road=0;
	for(int i=0;i<R;i++)
		for(int j=0;j<C;j++)
		{
			int max_temp=CountFunc(i,j);
			if(max_temp>max_road)
				max_road=max_temp;
			cout<<"value "<<data[i][j].value<<" road "<<max_temp<<endl;
			
		}

		
	return 0;
}

8、以下两个语句的区别是:第一个动态申请的空间里面的值是随机值,第二个进行了初始化,里面的值为0

int *p1 = new int[10];
int *p2 = new int[10]();

笔试总结:

(1)笔试需要的东西有,c++、 网络编程、sql 、linux 、数据结构与算法

(2)c++是基础

(2)其中linux、sql考一些简单的东西,网络编程考些填空选择题

(3)数据结构考的是一些大题,尤其重要。

 

以下部分为自己添加:

1、约瑟夫环的问题

#include "stdafx.h"
#include <iostream>
using namespace std;
struct ListNode
{
	int data;
	ListNode *next;
};
void CreateList(ListNode* &L)
{
	int a=0;	
	ListNode *p;
	bool f=false;
	int count=0;
	while(count<7)
	{	cin>>a;	
		count++;
		if(!f)//创建第一个节点,将L指向它
		{
			L=new ListNode();
			L->data=a;
			p=L;
			f=true;

		}
		else
		{
			ListNode *pNew=new ListNode();
			pNew->data=a;
			p->next=pNew;
			p=pNew; //将p移到最后一个
		}
		
	}
	//接成环
	p->next=L;

}
void PrintList( ListNode *L)
{
	ListNode *p=L;
	while(p->next != L)
	{
		cout<<p->data;
		p=p->next;
	}
	cout<<p->data<<endl;

}


void joseph(ListNode *L,int k,int m)
{
	int i=1;
	ListNode *p=L;
	while(i<k)
	{
		p=p->next;
		i++;
	}
	while(p)
	{
		int j=1;
		while(j<m-1)//指向前一个
		{
			p=p->next;
			j++;
		}
		if(p==p->next)//只剩最后一个元素
		{
			cout<<p->data;
			delete p;
			break;
		}
		else
		{
			ListNode *temp=p->next;
			p->next=temp->next;
			cout<<temp->data;
			p=p->next;
			delete temp;
		}

	}

}
int _tmain(int argc, _TCHAR* argv[])
{
	ListNode *L;
	CreateList(L);
	joseph(L,1,3);
	cout<<endl;
	//PrintList(L);


	return 0;
}


输出:

1 2 3 4 5 6 7
3627514
请按任意键继续. . .

思想:

(1)构建约瑟夫环,这里用链表来创建,注意没有头节点,传递第一个节点的引用指针,新建第一个节点,利用后插法,p指向最后一个节点,最后将p、L拼接成环。

(2)打印约瑟夫环,while(p->next!=L),再打印最后一个

(3)约瑟夫问题处理,利用计数器,定位开始位置--while,不断删除,减小环的大小,最后变成空的,用到两个while,注意最后一个的情况,如何判断指针里面有没有值,这个是个问题。

 

3、华为笔试

#include<iostream>
using namespace std;

int main()
{
	int n;
	//int a;
	//a=scanf("%d%",&n);//这种情况是用空格隔开
	//scanf("%d,%d",&n,&a); 这种情况是用,号隔开
	//cout<<n<<a<<endl;
	while(~scanf("%d,",&n))
	{    
		cout<<n<<" ";
	}
	cout<<"hello world"<<endl;
	system("pause");
	return 0;
}

 

4、腾讯笔试

(1)gcc -Daa 的问题

(2)find函数的问题,find(s.begin(),s.end(),'0')

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


int main()
{
	string a="fdfffop";
	if(a.end()==find(a.begin(),a.end(),'0'))
		cout<<"1"<<endl;
	system("pause");
	return 0;
}

这里的find函数为算法里面的,从第一个迭代器开始,到左后一个迭代器,找'0'第一次出现的位置,若找到则返回迭代器,否则返回最后一个迭代器。

(3)私有Ip的问题

私有ip总共有3种,这个题我做错了,

10.0.0.0  ~ 10.255.255.255

172.16.0.0 ~172.32.255.255

192.168.0.0 ~192.168.255.255

另外还有一个dhcp的问题,这个是给局域网自动分配ip的,这个题我做错了,其实对于一个公有ip而言,是可以不需要的,而现在子网掩码是必须的。

(4)对齐的问题

class B
{
public:
	char c1;
	short s[5];
	int a;
	char c2;
};

sizeof(B) 位20,这是因为s只能1个一个的拆 而其本身又占2个字节

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
class A
{
public:
	virtual void print(){}
	int a;
	char c;
};
class B:public A
{
	 void print(){}
	int a;
	char c;
};

int main()
{
	cout<<sizeof(B)<<endl;
	system("pause");
	return 0;
}


 

(5)rodis用的什么结构

(6)set

#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<array>
using namespace std;
int main()
{
	array<string,2> a={"12","32"};
	set<string> s(a.begin(),a.end());
	for(auto iter=a.begin();iter!=a.end();iter++)
	{
			string a1=*iter;
			cout<<a1;
	}

	system("pause");
	return 0;
}

思想:

set和vector类似,但是set一般适用于找一个元素,其迭代方式和vector是一样的,但是不能用at

一般用于找一个元素,find()函数若找到则返回当前迭代器,否则,返回.end()

c.erase(p) 其中p为迭代器,这个题做错了,肯定是迭代器要好的,这样就能删除哪些位置的元素了,另外的用法为erase(b,e),删除迭代器be之间的元素。


 

(7)二分查找的次数

最坏查找次数为 log2n+1;

(8)释放内存之后,会马上回收到os吗
 进程结束后,给其分配的内存肯定是立即回收的,即使是僵死进程,也不过是保留了它的 PCB(process control block),其他内存还是立即回收了的。

 (10)至少多少个人及格

100个人回答五道试题,有81人答对第一题,91人答对第二题,85人答对第三题,79人答对第四题,74人答对第五题,答对三道题或三道题以上的人算及格, 那么,在这100人中,至少有( )人及格。   

 答案:  分析:问至少有多少人及格,那就是说不及格的人数最多时及格的人数最少.100人回答5道题,相当于做500道题,共答对的题目数量有:81+91+85+79+74=410(道),则出错的数量有:500-410=90(道),错3道以上就不及格,每人错3道时不及格人数最多,90÷3=30(人),则及格的人数是:100-30=70(人)。   

这个题我不会做,要多用逆向思维。这是考验智商的题目了。

(11)猴子取香蕉的问题,一次取一个或者2个,取50个香蕉有多少种取法。

这里面涉及到组合的编程问题,我想应该是作对了,

排列的定义及其计算公式:从n个不同 元素中,任取m(m≤n,m与n均为自然数,下同)个元素按照一定的顺序排成一列,叫做从n个不同元素中取出m个元素的一个排列;从n个不同元素中取出m(m≤n)个元素的所有排列的个数,叫做从n个不同元素中取出m个元素的排列数,用符号 A(n,m)表示。A(n,m)=n(n-1)(n-2)……(n-m+1)= n!/(n-m)! 此外 规定0!=1(n!表示n(n-1)(n-2)...1,也就是6!=6x5x4x3x2x1[1] 
组合的定义及其计算公式:从n个不同元素中,任取m(m≤n)个元素并成一组,叫做从n个不同元素中取出m个元素的一个组合;从n个不同元素中取出m(m≤n)个元素的所有组合的个数,叫做从n个不同元素中取出m个元素的组合数。用符号 C(n,m) 表示。C(n,m)=A(n,m)/m!;C(n,m)=C(n,n-m)。(n≥m)
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
int main()
{
	int sum=0;
for(int i=25,j=0;i<=50,j<=50;i++,j+=2)//这里不能够写为j*=2,因为是不断加上2的,这里写错了,大问题啊
{	int temp=1;
	int ja=min(j,(50-j));
	for(int m=1,n=i;m<=ja;m++,n--)
	{
		temp*=n;
	}
	sum+=temp;
}
cout<<sum<<endl;
	system("pause");
	return 0;
}

这里尤其要注意的地方是,j+=2,所以说分析问题的时候,一定要注意一些地方,否则会出现重大事故。另外min需要头文件stdlib.h。最后这里for的一些初始化方式我觉得我写的不错。这个组合的形式我也比较喜欢。

这里进一步将其提取为一个函数:

int group(int i,int j)
{
	int temp=1;
	int ja=min(j,(50-j));
	for(int m=1,n=i;m<=ja;m++,n--)
	{
		temp*=n;
	}
	return temp;
}

非常好用。

(12)棋盘的最大正方形数目

int sum=0;
	for(int i=1;i<=19;i++)
	{
		sum+=i*i;
	}
	cout<<sum<<endl;

这个是没有问题的,答案是2470


新题
 1、http中有哪些方法是不安全的?
2、大话设计模式

3、接口。


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值