某公司ios开发笔试题真题及答案

匿名网友 匿名网友 发布于: 2015-11-30 00:00:00
阅读 162 收藏 0 点赞 0 评论 0

一、基础知识

1.引用与指针有什么区别?

答:

2、请写出下列代码的输出内容

#include<stdio.h>

main() {

int a,b,c,d;

a=11;

b=a++;

c=++a;

d=10*a++;

printf(“b,c,d:%d,%d,%d”,b,c,d);

return 0;

}

答:

3,下述三个有什么区别?

char * const p;

char const * p

const char *p

答:

4,改错:

#include <stdio.h>

int main(void) {

                int **p;

        int arr[100];

    
 

                p = &arr;

    

return 0;

}

答:

 

5. 写出程序运行结果

 

int sum(int a) {

auto int c=0;

static int b=3;

c+=1;

b+=2;

return(a+b+c);

}

 

void main() {

int I;

int a=2;

for(I=0;I<5;I++) {

printf(“%d,”, sum(a));

}

}

答:

6,阅读下面文字,回答问题

NSArray and its subclass NSMutableArray manage collections of objects called arrays. NSArray creates static arrays, and NSMutableArray creates dynamic arrays.

NSArray and NSMutableArray are part of a class cluster, so arrays are not actual instances of the NSArray or NSMutableArray classes but of one of their private subclasses. Although an array’s class is private, its interface is public, as declared by these abstract superclasses, NSArray and NSMutableArray.

Generally, you instantiate an array by sending one of the array… messages to either the NSArray or NSMutableArray class object. These methods return an array containing the elements you pass in as arguments. (Note that arrays can’t contain nil.) In general, objects that you add to an array aren’t copied; rather, each object receives a retain message before its id is added to the array. When an object is removed from an array, it’s sent a release message.

The NSArray and NSMutableArray classes adopt the NSCopying and NSMutableCopying protocols, making it convenient to convert an array of one type to the other.

NSArray’s two primitive methods—count and objectAtIndex:—provide the basis for all other methods in its interface. The count method returns the number of elements in the array; objectAtIndex: gives you access to the array elements by index, with index values starting at 0.

问题:

1)NSArray和NSMutableArray是什么关系?

答:

 

2)NSArray和c语言中的数组有什么区别?

答:

 

3)NSArray和NSMutableArray中的数据有什么限制条件?

 

 

二、数据库

1,表table1内容:

 

2005-05-09 胜

2005-05-09 胜

2005-05-09 负

2005-05-09 负

2005-05-10 胜

2005-05-10 负

2005-05-10 负

如果要生成下列结果, 该如何写sql语句?

        胜 负

2005-05-09     2 2

2005-05-10     1 2

 

答:

2,有一张表,里面有3个字段:语文,数学,英语。其中有3条记录分别表示语文70分,数学80分,英语58分,请用一条sql语句查询出这三条记录并按以下条件显示出来(并写出您的思路):

大于或等于80表示优秀,大于或等于60表示及格,小于60分表示不及格。

显示格式:

语文 数学 英语

及格 优秀 不及格

答:

 

三、算法

1,写一个快速排序的算法排列一个字符串数组(排列方法由大到小用ASCII码值做为比较),并计算它的时间复杂度和空间复杂度(写出具体的过程和快速排序的基本思想)

例如:char ARRAY[3]={‘D’,’A’,’C’};

排列后的结果为{‘A’,’C’,’D’};

     ASCII值 D>C>A

 

求以下数组的排列结果:

char array[10]={‘x’,’s’,’s’,’a’,’b’,’y’,’m’,’w’,’r’,’l’};

 

 

 

答案:


1,1) 引用必须被初始化,指针不必。

2) 引用初始化以后不能被改变,指针可以改变所指的对象。

3) 不存在指向空值的引用,但是存在指向空值的指针。

2,1113130

3, char * const p; //常量指针,p的值不可以修改

char const * p//指向常量的指针,指向的常量值不可以改

const char *p //char const *p一样, c++标准规定const关键字放在类型或变量名之前是等价的)

4,    解答:

搞错了,是指针类型不同,

int **p; //二级指针

&arr; //得到的是指向第一维为100的数组的指针

#include <stdio.h>

int main(void) {

int **p, *q;

int arr[100];

q = arr;

p = &q;

return 0;

}

5,    // static会保存上次结果,记住这一点,剩下的自己写

输出:8,10,12,14,16,

6,1)NSArrayNSMutableArray的父类

2NSArray中各元素的数据类型可以不同

3)不能添加空值


1,

1)select rq, sum(case when shengfu=’胜’ then 1 else 0 end)’胜’,sum(case when shengfu=’负’ then 1 else 0 end)’负’ from #tmp group by rq

2) select N.rq,N.勝,M.負 from (

select rq,勝=count(*) from #tmp where shengfu=’胜’group by rq)N inner join

(select rq,負=count(*) from #tmp where shengfu=’负’group by rq)M on N.rq=M.rq

3)select a.col001,a.a1 胜,b.b1 负 from

(select col001,count(col001) a1 from temp1 where col002=’胜’ group by col001) a,

(select col001,count(col001) b1 from temp1 where col002=’负’ group by col001) b

where a.col001=b.col001

2

select
(case when
语文>=80 then ‘优秀
        when
语文>=60 then ‘及格
else ‘
不及格‘) as 语文,
(case when
数学>=80 then ‘优秀
        when
数学>=60 then ‘及格
else ‘
不及格‘) as 数学,
(case when
英语>=80 then ‘优秀
        when
英语>=60 then ‘及格
else ‘
不及格‘) as 英语,
from table

 


1,基本思想:

 

快速排序是对冒泡排序的一种本质改进。它的基本思想是通过一趟扫描后,使得排序序列的长度能大幅度地减少。在冒泡排序中,一次扫描只能确保最大数值的数移到正确位置,而待排序序列的长度可能只减少1。快速排序通过一趟扫描,就能确保某个数(以它为基准点吧)的左边各数都比它小,右边各数都比它大。然后又用同样的方法处理它左右两边的数,直到基准点的左右只有一个元素为止。

 

时间复杂度和空间复杂度分析:

快速排序每次将待排序数组分为两个部分,在理想状况下,每一次都将待排序数组划分成等长两个部分,则需要logn次划分。

而在最坏情况下,即数组已经有序或大致有序的情况下,每次划分只能减少一个元素,快速排序将不幸退化为冒泡排序,所以快速排序时间复杂度下界为O(nlogn),最坏情况为O(n^2)。在实际应用中,快速排序的平均时间复杂度为O(nlogn)。

快速排序在对序列的操作过程中只需花费常数级的空间。空间复杂度S(1)。

但需要注意递归栈上需要花费最少logn 最多n的空间

 

算法:

void quick_sort_char(char data[], int low, int high)

{

int i, j,pivot;

 

if (low < high)

{

pivot=(int)data[low];

i=low;

j=high;

 

while(i<j)

{

while (i<j && (int)data[j]>=pivot)

j–;

if(i<j)

data[i++]=data[j]; //将比枢轴记录小的记录移到低端

 

while (i<j && (int)data[i]<=pivot)

i++;

if(i<j)

data[j–]=data[i]; //将比枢轴记录大的记录移到高端

}

 

data[i]=(char)pivot; //枢轴记录移到最终位置

 

quick_sort_char(data,low,i-1);

quick_sort_char(data,i+1,high);

}

}

评论列表
文章目录