|
网友A分享的网易笔试题: 1、10个人分成4组 有几种分法? 2、如图: 7 8 9 10 6 1 2 11 5 4 3 12 16 15 14 13 设“1”的坐标为(0,0) “7”的坐标为(-1,-1) 编写一个小程序,使程序做到输入坐标(X,Y)之后显本文由论文联盟http://www.LWlm.com收集整理示出相应的数字。 3、#include //example input and output //in 1 2 3 out 1 3 1 //in 123456789 2 100 out 123456789 100 21 long mex(long a,long b,long c) { long d; if(b==0) return 0; if(b==1) return a%c; d=mex(a,b/2,c); d*=d;这里忘了;d*=mex(a,b%2,c);d%=c; return d; } int main(void) { long x,y,z; while(1) { if(scanf(%d %d %d,&x,&y,&z)>3) return 0; if(x<0) { printf("too small\n");continue;} if(y<0) { printf("too small\n");continue;} if(z<1) { printf("too small\n");continue;} if(y>z) { printf("too big\n");continue;} if(z>1000000010) {printf("too big\n");continue} printf(%d %d %d,x,z,mex(x,y,z); }} 根据这个程序,当已知一个输入,算出输出,如:输入 1 3 1 则输出 1 2 3 输入 123456789 100 21 输出 123456789 2 100
网友B分享的网易笔试题:
1. #i nclude 和#i nclude “filename.h” 有什么区别? 答:对于#i nclude ,编译器从标准库路径开始搜索filename.h 对于#i nclude “filename.h”,编译器从用户的工作路径开始搜索filename.h 2. 在C++ 程序中调用被C 编译器编译后的函数,为什么要加extern “C”? 答:C++语言支持函数重载,C 语言不支持函数重载。函数被C++编译后在库中的名字与C 语言的不同。假设某个函数的原型为: void foo(int x, int y); 该函数被C 编译器编译后在库中的名字为_foo , 而C++ 编译器则会产生像_foo_int_int 之类的名字。 C++提供了C 连接交换指定符号extern“C”来解决名字匹配问题。 3. 一个类有基类、内部有一个其他类的成员对象,构造函数的执行顺序是怎样的? 答:先执行基类的(如果基类当中有虚基类,要先执行虚基类的,其他基类则按照声明派生类时的顺序依次执行),再执行成员对象的,最后执行自己的。 4. New delete 与malloc free 的区别 答案:用malloc 函数不能初始化对象,new 会调用对象的构造函数。Delete 会调用对象的destructor,而free 不会调用对象的destructor. 5. Struct 和class 的区别 答案:struct 中成员变量和成员函数默认访问权限是public,class 是private 6.请问下面程序有什么错误? int a[60][250][1000],i,j,k; for(k=0;k<=1000;k++) for(j=0;j<250;j++) for(i=0;i<60;i++) a[i][j][k]=0; 答案:把循环语句内外换一下 7. 请写出下列代码的输出内容 #include main() { int a,b,c,d; a=10; b=a++; c=++a; d=10*a++; printf("b,c,d:%d,%d,%d",b,c,d); return 0; } 答:10,12,120 8. 写出BOOL,int,float,指针类型的变量a 与零的比较语句。 答案: BOOL : if ( !a ) int : if ( a == 0) float : const EXPRESSION EXP = 0.000001 if ( a < EXP && a >-EXP) pointer : if ( a != NULL) 9.已知strcpy 函数的原型是: char *strcpy(char *strDest, const char *strSrc); 其中strDest 是目的字符串,strSrc 是源字符串。不调用C++/C 的字符串库函数,请编写函数 strcpy 答案: char *strcpy(char *strDest, const char *strSrc) { if ( strDest == NULL || strSrc == NULL) return NULL ; if ( strDest == strSrc) return strDest ; char *tempptr = strDest ; while( (*strDest++ = *strSrc++) != ‘’) ; return tempptr ; } 10.写一个函数找出一个整数数组中,第二大的数 答案: const int MINNUMBER = -32767 ; int find_sec_max( int data[] , int count) //类似于1 4 4 4这样的序列将认为1是第二大数 { int maxnumber = data[0] ; int sec_max = MINNUMBER ; for ( int i = 1 ; i < count ; i++) { if ( data[i] > maxnumber ) { sec_max = maxnumber ; maxnumber = data[i] ; } else { if ( data[i] > sec_max ) sec_max = data[i] ; } } return sec_max ;
} (责任编辑:职场达人) |


