哪个网站简历做的好淘大象排名查询
个人认为有趣的题的总结,希望对大家有帮助。
原文地址:http://blog.csdn.net/callon_h/article/details/52430312
1. 蛇形矩阵
题目大意:给一个边长n,给出1-n^2的数字蛇形数据,如下
n=3
output:
1 2 3
8 9 4
7 6 5
此题后来发现在另一篇博文中
http://blog.csdn.net/z_x_b5/article/details/51056536?locationNum=1
也有记录,思想接近,不过用的方法不尽相同吧,大家参考参考即可:
- #include <stdio.h>
- int Ori_width,New_width;
- void resort(int *temp, int *temp1){
- int i,j;
- if(New_width == 1 || New_width == 0){
- if(New_width == 0)
- return;
- *temp1 = Ori_width*Ori_width;
- return;
- }
- else
- { //right
- for(i=0;i<New_width;i++)
- *(temp1+i)=*(temp+i);
- //down
- for(i=0;i<New_width-1;i++)
- *(temp1+New_width-1+(i+1)*Ori_width)=*(temp+New_width+i);
- //left
- for(i=0;i<New_width-1;i++)
- *(temp1+Ori_width*(New_width-1)+New_width-2-i)=*(temp+2*New_width-1+i);
- //up
- for(i=0;i<New_width-2;i++)
- *(temp1+(New_width-2-i)*Ori_width)=*(temp+3*New_width-2+i);
- New_width -= 2;
- resort(temp+4*(New_width+1),temp1+Ori_width+1);
- }
- }
- int main()
- {
- int i,j;
- printf("hello world!\n");
- while(1){
- printf("****************\n");
- printf("****************\n");
- printf("Please input your width of matrix: ");
- scanf("%d",&Ori_width);
- New_width = Ori_width;
- printf("width is %d\n",Ori_width);
- do{
- int Ori_matrix[Ori_width][Ori_width],Sorted_matrix[Ori_width][Ori_width];
- for(i=1;i<=Ori_width;i++){
- for(j=1;j<=Ori_width;j++){
- Ori_matrix[i-1][j-1] = (i-1)*Ori_width + j;
- Sorted_matrix[i-1][j-1] = Ori_matrix[i-1][j-1];
- }
- }
- resort(*Ori_matrix,Sorted_matrix[0]);
- for(i=1;i<=Ori_width;i++){
- for(j=1;j<=Ori_width;j++){
- printf("%d ",Sorted_matrix[i-1][j-1]);
- }
- printf("\n");
- }
- printf("\n");
- }while(0);
- }
- return 0;
- }
2. java知识考察
在腾讯的2016.9.1模拟考中的选择题
有如下代码:
- public static void main(String[] args){
- Integer i1=127,i2=127,i3=128,i4=128;
- System.out.println(i1==i2);
- System.out.println(i1.equals(i2));
- System.out.println(i3==i4);
- System.out.println(i3.equals(i4));
- }
如果java掌握不牢固,这道题也很难答,乍一看两个==和两个equals至少是两个true或者两个false或者全true全false吧?
但是,判断结果该是:true true false true。
理由:==总在基本数据类型时比较的是两个数据值是否相同(.equals在object类中比较的是地址,但是子类一般都会重写它,在基本数据类型中表示的是值的大小是否一样),如果用在引用类型时比较的是地址是否相同,也就是比较两个对象的引用是否相同,为了节省内存,java设计了基本数据类型包装类的缓存,JVM会自动维护8种基本类型的缓存/常量池,大概意思是程序启动时,这些数值已经放在缓存池中,你new 一个Integer对象,它首先去缓存去查,如果有的话,直接将新new出的对象引用指向缓存池中的对象,Integer缓存的范围是[-128,127],超出范围就需要重新在堆内存中new了。所以当为i=127赋值时,在自动装箱过程中是取自常量池/缓存池中的数值,而当i=128时,128不在常量池范围内,所以在自动装箱过程中需要new128,所以地址不一样。
3.数据库知识
在RR2016.9.5笔试题中
数据库系统中,产生数据不一致的根本原因是:数据冗余。
理由:首先,数据不一致性是指数据的矛盾性、不相容性。
产生数据不一致的原因主要有以下三种:一是由于数据冗余造成的;二是由于并发控制不当造成的;三是由于各种故障、错误造成的。但根本原因是:数据冗余。
4.二叉树遍历
在RR2016.9.5笔试题中
已知前序遍历aebdc,后序遍历bcdea,根节点下的子节点有?
只有e。
理由:首先了解什么是前序、中序和后序遍历,总的来说就是NLR、LNR和LRN。L为访问左结点,R为访问右结点,N为访问本结点。知道这个之后来看这个问题:根据前序或后续序列,可以确定a必定有一个子结点e,假设e为左孩子,a右孩子不为空,则后续遍历序列中与a相邻的应该为a的右孩子。同理,假设e为右孩子,a的左孩子不为空,则先序遍历时与a相邻的为a的左孩子。故a有且只有e这一个孩子,左右无法确定。
同样是RR2016.9.5笔试
已知前序遍历aebdc,中序遍历becda,后序遍历:______________。
bcdea。
理由:有时候遍历会迷糊,但是掌握程序的本质写法是递归之后,也就不会迷惑了。
5.IP知识
在RR2016.9.5笔试题中
某主机的IP地址为202.117.131.12/20,其子网掩码是多少?
255.255.240.0。
理由:默认子网掩码是255.255.255.0,但是最后的/20限定了前面只能有20个1,那么255是8位,所以至少有2个255,最后四个1应该是128+64+32+16=240,最后得到255.255.240.0。
同样是RR2016.9.5笔试
IP地址159.226.181.1是____A类?B类?C类?D类?IP地址。
B类。
理由:A类IP地址范围:1.0.0.1 - 126.255.255.254。B类:128.1.0.1 - 191.255.255.254。C类: 192.0.1.1 - 123.255.255.254。
6.指针数组
还是RR2016.9.5的笔试题,这个比较简单,
求一个程序的输出:
- int a[4][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
- int (*ptr)[3];
- ptr = (int (*)[3])a;
- printf("result is %d\n",a[3][1] - ptr[3][1]);
理由:在ptr看来是这样的:
1 2 3
4 5 6
7 8 9
10 11 12
...
14-11=3。
7.进程死锁
在某银行2016.9.6笔试题中
若系统中有5个进程共享若干个资源R,每个进程都需要4个资源R,那么使系统不发生死锁的资源R的最少数目是_______。
16。
理由:假设系统为每个进程各分配了3个R,此时只需要再有1个R就能保证有一个进程可以运行,进程运行完毕后释放占有的所有资源,其他进程又可以运行,直到所有进程运行完毕。
8.可能出栈顺序
某银行2016.9.6笔试题中(其他也考过)
若进栈序列为e1,e2,e3,e4,那么可能的出栈顺序_____。
一般为选择题,此时只介绍方法,如果先出来的是e3,那么证明e2,e1早就压栈了,后面肯定不能接e1,因为e1在e2下面,如此逻辑推理即可。
9.简单练习——C调序
在新美大的网上测试中,
输入一个整数数组,调整数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数位于数组的后半部分,要求时间复杂度为O(n)。
输入包含一行,为逗号隔开的一个或者多个整数,取值范围为[1,100]。如:
1,2,3,4
输出包含一行,同样为逗号隔开的一个或者多个整数。如:
1,3,2,4
- #include <stdio.h>
- #define MAX_LEN 1000
- int main()
- {
- char end;
- int arr[MAX_LEN];
- int temp=0,i =0,j=0,k=0;
- do{
- scanf("%d",&arr[i++]);
- if(arr[i-1]>100)
- arr[i-1]=100;
- else if(arr[i-1]<1)
- arr[i-1] = 1;
- }while((end = getchar())!='\n');
- while(1)
- {
- for(j=0;j<i;j++)
- {
- if(arr[j]%2==0)
- break;
- }
- for(k=i-1;k>0;k--)
- {
- if(arr[k]%2==1)
- break;
- }
- if(j<k)
- {
- temp=arr[j];
- arr[j]=arr[k];
- arr[k]=temp;
- }
- else
- {
- break;
- }
- }
- for(j=0;j<i;j++)
- if(j!=(i-1))
- printf("%d,",arr[j]);
- else
- printf("%d\n",arr[j]);
- return 0;
- }
运行结果:
10.简单练习——二维卷积
同样在新美大的网上测试中,
题目太长,原谅我就打要求吧:
要求输入矩阵A[m*n],卷积核h[k*k],m>k且n>k;输出卷积后矩阵。
输入包括三行:
第一行为三个正整数,空格隔开,分别为k,m,n,取值范围为[1,100];
第二行为m*n个正整数,空格隔开,为输入矩阵A的各元素值,取值范围为[1,100];
第三行为k*k个正整数,空格隔开,为卷积核矩阵h的各元素值,取值范围为[1,100]。
如:
2 3 3
1 2 1 0 2 2 2 1 1
-1 1 1 -1
输出包括一行,按顺序输出矩阵B每行的元素值,空格隔开,如:
-1 -1 3 0
- #include <stdio.h>
- #define MAX_LEN 1000
- int main()
- {
- int temp[3];
- int k,m,n;
- int i,j,row,col;
- for(i=0;i<3;i++){
- scanf("%d",&temp[i]);
- if(temp[i]>100)
- temp[i] = 100;
- else if(temp[i]<1)
- temp[i] = 1;
- }
- k=temp[0];
- m=temp[1];
- n=temp[2];
- //:can delete
- if(m<=k)
- m=k+1;
- if(n<=k)
- n=k+1;
- //:~
- do{
- int A[m][n];//input
- int h[k][k],t[k][k];
- int B[m-k+1][n-k+1];//output
- for(row=0;row<(m-k+1);row++)
- for(col=0;col<(n-k+1);col++)
- B[row][col] = 0;
- for(i=0;i<m;i++){
- for(j=0;j<n;j++){
- scanf("%d",&A[i][j]);
- if(A[i][j]>100)
- A[i][j] = 100;
- else if(A[i][j]<-100)
- A[i][j]=-100;
- }
- }
- for(i=0;i<k;i++){
- for(j=0;j<k;j++){
- scanf("%d",&h[i][j]);
- if(h[i][j]>100)
- h[i][j] = 100;
- else if(h[i][j]<-100)
- h[i][j]=-100;
- }
- }
- for(row=0;row<(m-k+1);row++){
- for(col=0;col<(n-k+1);col++){
- for(i=0;i<k;i++)
- for(j=0;j<k;j++)
- t[i][j] = A[i+row][j+col]*h[i][j];
- for(i=0;i<k;i++)
- for(j=0;j<k;j++)
- B[row][col] += t[i][j];
- }
- }
- for(row=0;row<(m-k+1);row++)
- for(col=0;col<(n-k+1);col++)
- printf("%d ",B[row][col]);
- printf("\n");
- }while(0);
- return 0;
- }
11.初级算法
目前没有直接考的,但是有些题是它的变种——硬币找零。
在某个找零机器内存有n个值为V1,V2,V3,...的硬币,当有人拿出值为T的钱需要找零时,求问找零的硬币最少需要多少?由哪些硬币组成?
- #include <stdio.h>
- #define MAX_TYPE 100
- #define PRINT
- //Just review shellsort, not necessary.
- void shellsort(int *arr,int size)
- {
- int h=1,i=0;
- while(h<size)
- {
- h=3*h+1;
- }
- h=(h-1)/3;
- while(h>0)
- {
- for(i=0;(i+h)<size;i++)
- {
- if(arr[i+h]>arr[i])
- {
- int temp = arr[i+h];
- arr[i+h] = arr[i];
- arr[i] = temp;
- }
- }
- h=(h-1)/3;
- }
- }
- void makeChange(int *moneytype,int typenum,int money,int *coin)
- {
- int i,k,min;
- #ifdef PRINT
- int j,n,flag;
- int arr[money+1][money+1];
- arr[0][0] = 0;
- flag = 0;
- #endif
- coin[0] = 0;
- for(i=1;i<money+1;i++)
- {
- min = i;
- for(k=0;k<typenum;k++)
- {
- if(moneytype[k] <= i)
- {
- int temp = coin[i-moneytype[k]]+1;
- if(temp < min)
- {
- min = temp;
- #ifdef PRINT
- flag = 1;
- j = k;
- #endif
- }
- }
- }
- coin[i] = min;
- #ifdef PRINT
- if(flag == 1)
- {
- for(n=0;arr[i-moneytype[j]][n]!=0;n++)
- arr[i][n] = arr[i-moneytype[j]][n];
- arr[i][n] = moneytype[j];
- arr[i][n+1] = 0;
- flag = 0;
- }
- if(coin[i] == i)
- {
- for(n=0;n<i;n++)
- arr[i][n] = 1;
- arr[i][i] = 0;
- }
- #endif
- }
- printf("如果我们要找%d的钱,我们最少需要使用%d个币\n",money,coin[money]);
- #ifdef PRINT
- printf("需要零的钱为:");
- for(n=0;n<coin[money];n++)
- printf("%d ",arr[money][n]);
- printf("\n");
- #endif
- }
- int main()
- {
- char end;
- int changeType[MAX_TYPE],TotalMoney;
- int i=0,j=0;
- printf("有哪几种硬币(不超过100种):");
- do{
- scanf("%d",&changeType[i++]);
- }while((end=getchar())!='\n');
- printf("Now Machine has ");
- //shellsort(changeType,i);
- for(j=0;j<i;j++)
- {
- printf("%d ",changeType[j]);
- }
- printf(",%d types of money\n",i);
- while(1)
- {
- printf("输入总钱数,我会帮你找到最佳找零方法:");
- scanf("%d",&TotalMoney);
- do{
- int MinCoins[TotalMoney+1];
- makeChange(changeType,i,TotalMoney,MinCoins);
- }while(0);
- }
- return 0;
- }
12.链表操作
没有完全考到这部分的,但是相关的还是不少。
以Linux内核链表为例复习。
- #include <stdio.h>
- struct list_head{
- struct list_head *next,*prev;
- };
- struct score{
- int No;
- int english;
- int chinese;
- int math;
- struct list_head list;
- };
- struct list_head header;
- struct score stu1,stu2,stu3;
- struct list_head *slider;
- struct score *tmp;
- void Init_List_Head(struct list_head *head)
- {
- head->next = head;
- head->prev = head;
- }
- void __list_add(struct list_head *nw, struct list_head *prev, struct list_head *next)
- {
- next->prev = nw;
- nw->next = next;
- nw->prev = prev;
- prev->next = nw;
- }
- void list_add_tail(struct list_head *nw, struct list_head *head)
- {
- __list_add(nw,head->prev,head);
- }
- void list_add_top(struct list_head *nw, struct list_head *head)
- {
- __list_add(nw,head,head->next);
- }
- int main()
- {
- Init_List_Head(&header);
- stu1.No = 1;
- stu1.chinese = 89;
- stu1.english = 90;
- stu1.math = 98;
- list_add_tail(&stu1.list,&header);
- stu2.No = 2;
- stu2.chinese = 12;
- stu2.english = 13;
- stu2.math = 14;
- list_add_top(&stu2.list,&header);
- stu3.No = 3;
- stu3.chinese = 69;
- stu3.english = 80;
- stu3.math = 74;
- list_add_tail(&stu3.list,&header);
- for(slider=header.next;slider!=&header;slider=slider->next){
- const typeof(((struct score *)0)->list) *__mptr = slider;
- tmp = (struct score *)((char *)__mptr - (unsigned int)&(((struct score*)0)->list));
- printf("No is %d,english is %d,math is%d\n",tmp->No,tmp->english,tmp->math);
- }
- return 0;
- }