from:http://blog.sina.com.cn/s/blog_7ebe664201015yzl.html
立方体是三维度,长宽高各切一组,5的要切成1需要4刀,3组就是12刀
nxnxn切1x1x1的算式:3x(n-1)
******************************************************************************************************************************************
3、以下的代码可放在VC++6.0里面运行。题目是要求输出:TrendMicroSoftUSCN 然后要求修改程序,使程序能输出以上结果.代码如下:
#include <iostream>
#include <string>
using namespace std;
int main(int argc,char * argv[])
{
string strArr1[]={ “Trend “, “Micro “, “soft “};
string *p=new string[2];
p[0]= “US “;
p[1]= “CN “;
cout < <sizeof(strArr1) < <endl;
cout < <sizeof(p) < <endl;
cout < <sizeof(string) < <endl;
for(int i=0;i <sizeof(strArr1)/sizeof(string);i++)
cout < <strArr1;
for(i=0;i <sizeof(p)/sizeof(string);i++)
cout < <p;
cout < <endl;
}
首先要明确sizeof 不是函数,也不是一元运算符,他是个类似宏定义的特殊关键字,sizeof();括号内在编译过程中是不被编译的,而是被替代类型,如
int a=8;sizeof(a);在编译过程中,它不管a的值是什么,只是被替换成类型 sizeof(int); 结果为4.如果sizeof(a=6);呢,也是一样的转换成a的类型,但是要注意 因为a=6是不被编译的,所以执行完sizeof(a=6);a的值还是8,是不变的!
记住以下几个结论:
1. unsigned影响的只是最高位bit的意义(正负),数据长度不会被改变的。所以sizeof(unsigned int) ==
2. 自定义类型的sizeof取值等同于它的类型原形。如typedef short WORD;sizeof(short) == sizeof(WORD)。
3. 对函数使用sizeof,在编译阶段会被函数返回值的类型取代。如:int f1(){return 0;};
cout < <sizeof(f1()) < <endl; // f1()返回值为int,因此被认为是int
4. 只要是指针,大小就是4。如:cout < <sizeof(string*) < <endl; // 4
5. 数组的大小是各维数的乘积*数组元素的大小。如:
char a[] = “abcdef “;
int b[20] = {3, 4};
char c[2][3] = { “aa “, “bb “};
cout < <sizeof(a) < <endl; // 7
cout < <sizeof(b) < <endl; // 20*4
cout < <sizeof(c) < <endl; // 6
数组a的大小在定义时未指定,编译时给它分配的空间是按照初始化的值确定的,也就是7,包括‘\0’的。
6. 字符串的sizeof和strlen,用例子说明:
char a[] = “abcdef “;
char b[20] = “abcdef “;
string s = “abcdef “;
cout < <strlen(a) < <endl; // 6,字符串长度
cout < <sizeof(a) < <endl; // 7,字符串容量
cout < <strlen(b) < <endl; // 6,字符串长度
cout < <sizeof(b) < <endl; // 20,字符串容量
cout < <sizeof(s) < <endl; // 16, 这里不代表字符串的长度,而是string类的大小
cout < <strlen(s) < <endl; // 错误!s不是一个字符指针。
a[1] = ‘\0 ‘;
cout < <strlen(a) < <endl; // 1
cout < <sizeof(a) < <endl; // 7,sizeof是恒定的
所以sizeof(p)只是指针大小 为4, 要想求出数组p指向数组的成员个数,应该为sizeof(*p)*2/sizeof(string),为什么?指针p指向数组,则*p就是指向数组中的成员了,成员的类型是什么,string型,ok那么sizeof(*p)为16,乘以2才是整个数组的大小。
******************************************************************************************************************************************
4、There is binary search tree which is used to store characters ‘A’, ‘B’,‘C’,'D’,'E’,'F’,'G’,'H’,which
of the following is post-order tree walk
A. ADBCEGFH
B. BCAGEHFD
C. BCAEFDHG
D. BDACEFHG
E. All of above
右子树所有结点值都大于该结点值
结合二叉树后序遍历的特点, 最后一个肯定是根结点
A. ADBCEGFH
-> (H) 左子树(ADBCEGF), 右子树(空) (左子树必须都小于根H, 右子树都大于根H)
--> (F) 左子树 (ADBCE), 右子树(G)
---> (E) 左子树 (ADBC), 右子树(空)
----> (C) 剩下(ADB)不能区别左子树, 右子树, 所以选项A不成立
B. BCAGEHFD
->(D, (BCA), (GEHF))
--> GEHF, F为根, 剩下GEH不能根据F分成两个子段, 所以B不成立
C. BCAEFDHG
->(G, (BCAEFD), (H))
-->(G, (D, (BCA), (EF)), (H))
--->(G, (D, (A, (), (BC)), (F, (E), ())), (H))
---->(G, (D, (A, (), (C, (B), ())), (F, (E), ())), (H))
选项(C)成立
D. BDACEFHG
-> (G, (BDACEF), (H))
--> (G, (F, (BDACE), ()), (H))
---> (G, (F, (E, (BDAC), ()), ()), (H))
----> BDAC子树, C为根, 据C不能将序列BDA划分为两个子序列, 使得左子序列全小于C, 右子序列全大于C
所以选项(D)不成立.
最终答案选C
process A has arrived in the system, in that order; at time
D
(在0时刻,进程A进入系统,按照这个顺序,在30时刻,进程B和进程C也抵达;在90时刻,进程D和进程E也抵达。一个时间片是10个单元)
Process A requires 50 units of time in the CPU;
Process B requires 40 units of time in the CPU;
Process C requires 30 units of time in the CPU;
Process D requires 20 units of time in the CPU;
Process E requires 10 units of time in the CPU;
进程A需要占用CPU50个单元;
进程B需要占用CPU40个单元;
进程C需要占用CPU30个单元;
进程D需要占用CPU20个单元;
进程E需要占用CPU10个单元;
Which of the process will be the LAST to complete, if scheduling policy
preemptive SJF (Short Job First).please describe the principle.
(如果按照短作业优先级的方法,哪个进程最后结束。请描述原理)
C(30) 50-80
B(10) 80-90
E(10) 90-100
D(20) 100-120
B(30) 120-150
club is used to simulate guest in a club. With 0 guests
to wait outside;when some guests leave the waiting list will decrease. The function will print out number of guests in the club and waiting
void club(int x); positive x stands for guests
arrived, nagative x stands for guests left from within the club
(club函数用来模拟一个俱乐部的顾客。初始化情况下是0个顾客,俱乐部最大规模只能有50个顾客,当用户超过了最大规模,他们必须等在外面。当一些顾客离开了等待队列将减少。这个club函数将打印在俱乐部里面的顾客人数,和外面的等待人数。函数声明如下:
void club(int x);正数x代表客人来了,负数x代表客人离开了俱乐部)
For example, club (40) prints 40,0; and then club (20) prints 50,10; and
then club (-5) prints 50,5; and then club (-30) prints 25,0; and then
club (-30) prints N/A; since it is impossible input.
(举例而言:club (40)打印40,0;接着club (20)打印50,10;接着club (-5)打印50,5;
Please write the void club(int x) with c++;
To make sure this function works as defined, we have following set of
to pass into the function and check the result are correct.
(请用c++编程实现club函数。为了确保函数工作正常,我们使用下列数据来测试函数是否正常,你认为该选哪个选项)
a 60
b 20 50 -10
c 40 -30
d 60 -5 -10 -10 10
e 10 -20
f 30 10 10 10 -60
g 10 10 10
h 10 -10 10
A: a d e g
B: c d f g
C: a c d h
D :b d g h
E :c d e f
分析:
跟测试有关,看有没有覆盖所有的边界条件
设A为成员, B为排队
C1 0 0
C2 <50(Up/Down) 0
C3 50 >0(Up/Down)
a 60 适用C3 *
b 20 50 -10 适用C2\C3
c 40 -30 适用C2 *
d 60 -5 -10 -10 10 适用C3\C2
e 10 -20 适用C1 *
f 30 10 10 10 -60 适用C1\C2\C3
g 10 10 10 适用C2
h 10 -10 10 适用C2
a e [c|g|h]
显然e一定要
看了楼上的分析,我也说说,看看条件,第一感觉,肯定要包含e,因为只有他能测N/A的情况,一下就排除了B C D三项,再看A和E,差别在a和c,g和f的选取上,很显然,d包含a,f包含g,所以排除A,最终确定E
**************************************************************************************************
7、The following C++ code tries to count occurence of each ASCII charcater
void histogram(char* src)
{
}
If there may be some issue in the code above, which line(s) would be?
A 1 and 3
B 3 and 7
C 9
D 5 and 7
E 4 and 8
改为
hist[*src++]++;
grammar (如下语法)
S–> aSbS|bSaS|V (S是变量)
where V means a terminator for grammar.(V是一个语法的终止符)
which statement(s) below is(are) corrects?(下列哪种说法是正确的)
1. This grammar is not an ambiguous grammar (这个语法不是一个含糊的语法)
2. Sentence ‘abba’ can be constructed by only one parse tree(语句abba能被构造成一个分析树)
3. This grammar construct sentence contain any ‘a’ (1 and more) and any ‘b’ (1 and more)(这个语法构造句
4. The grammar equals to regular expression “(a|b)?(a|b)+”(这个语法等于正则表达式(a|b)?(a|b)+)
A :1
data
{
unsigned char x;
unsigned short y;
unsigned int z;
}
已知变量var类型为struct data;程序在32位上编,不考虑对齐,请补齐下面汇编语
言,以完成相应C语言功能
var.x=0;
LEA EBX, var
XOR EAX, ______
MOV [EBX], ______
var.y = (unsigned short) (var.z+1)
MOV ECX, ______
INC ECX
MOV ______, ______
var.z = var.y-1;
MOV DX, ______
AND EDX, ______
DEC, EDX
MOV ______, EDX
code
#include
#define VOID_P 0
#if VOID_P
void allocm(void *pout, unsigned long size)
{
}
#else
void allocm(void **pout, unsigned long size)
{
}
#elseif
int main(int argc, char *argv[]){
#if VOID_P
#else
#endif
}
分析:定义#define VOID_P 0
编译通过C/C++代码:
#include <iostream>
using namespace std;
#define VOID_P 0
#if VOID_P
void allocm(void *pout, unsigned long size)
{
}
#else
void allocm(void **pout, unsigned long size)
{
}
#endif
int main(int argc, char *argv[]){
#if VOID_P
#else
#endif
}
**************************************************************************************************
11、请编C++实现:函数可变长有序数组的插入(无重复数据节点)
int *head = NULL;
int Insert = (int **pHead, int n);
//参数:*pHead 数组首地址 n 插入数值
//返回值: 0成功, 1失败
分析:测试通过C/C++代码: