填空题 有STL库由哪部分组成,
简答题:1.冒泡排序和快速排序的优缺点
2.进程和线程共同使用的技术(好像是这么说的)
3.指针和引用的区别
4.析构函数和普通成员函数的区别
编程题(c,c++,java都可以,但不能用库函数)
1.识别一个字节中按位置1的个数,尽量用高效率的方法实现
2.编程实现一个类中只能实例化3次
3.实现一个字节中空格个数不能超过一个,例如a--b-c应该输出a-b-c,此处-代表空格
#include<stdio.h>
int main(int argc,char *argv[])
{
char a = 0x1f;
int n = 0;
while(a)
{
//n += a & 0x01;
//a >>= 1;
a &= a-1;
n++;
}
printf("%d\n",n);
return 0;
}
#include<iostream>
class finalclass
{
public: static int count;
public:
static finalclass *getinstance()
{
if(count <= 0)
return NULL;
count--;
return new finalclass;
}
static void setcount(int n)
{
count = n;
}
/* static void deleteinstance(finalclass *pinstance)
{
delete pinstance;
pinstance = 0;
}
*/
private:
finalclass(){}
~finalclass(){}
};
int finalclass::count = 0;
int main()
{
finalclass::setcount(3);
finalclass *f1 = finalclass::getinstance();
finalclass *f2 = finalclass::getinstance();
finalclass *f3 = finalclass::getinstance();
if(f3 == NULL)
printf("f3 NULL\n");
else
printf("f3 NOT NULL\n");
finalclass *f4 = finalclass::getinstance();
if(f4 == NULL)
printf("f4 NULL\n");
finalclass *f5 = finalclass::getinstance();
if(f5 == NULL)
printf("f5 NULL\n");
}
#include<stdio.h>
int main(int argc,char *argv[])
{
char str[128] = "a b c";
int state = 0,i = 0;
printf("%s\n",str);
while(str[i])
{
if(state == 0 && str[i-1] == ' ' && str[i] == ' ')
state = 1;
if(state == 1 && str[i] != ' ')
state = 0;
if(state == 0)
printf("%c",str[i]);
i++;
}
return 0;
}
#include<stdio.h>
char str[128] = "./a.out 100 200";
int argc = 0,state = 0,i = 0;
char *argv[20] = {};
void parse()
{
while(str[i])
{
if(state == 0 && str[i] != ' ')
{
state = 1;
argv[argc++] = str + i;
}
if(state == 1 && str[i] ==' ')
{
state = 0;
str[i] = '\0';
}
i++;
}
}
int main(void)
{
printf("%s\n",str);
parse();
printf("argc=%d\n",argc);
for(i = 0;i < argc;i++)
printf("%s\n",argv[i]);
}