Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4983318
  • 博文数量: 1696
  • 博客积分: 10870
  • 博客等级: 上将
  • 技术积分: 18357
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-30 15:16
文章分类
文章存档

2017年(1)

2016年(1)

2015年(1)

2013年(1)

2012年(43)

2011年(17)

2010年(828)

2009年(568)

2008年(185)

2007年(51)

分类: IT职场

2010-06-04 10:43:06

 c/c++ 工程师:
 
第一题:
      123456789的二进制是“00000111010110111100110100010101”,前面的0是无效的,用c语言 写一个函数算出里面有多少个0?
答案:
     这个用循环以为做的话,O(n)>>S(n),用下面的程序可以实现以空间换取时间。

#include

int ComputeZero(int a)
{
     int b,count=0;
     while(a>=16)
      {
   b=a%16;
   a=a/16;
         switch(b){
   case 0:count+=4;break;
         case 1:
   case 2:
   case 4:
   case 8:count+=3;break;
   case 3:
   case 5:
   case 6:
   case 9:
   case 10:
   case 12:count+=2;break;
   case 7:
   case 11:
   case 13:
      case 14:count+=1;break;
   default:break;
   }
  }
  switch(a)
  {
  case 2:
  case 5:
     case 6:count+=1;break;
  case 4:count+=2;break;
  default:break;
  }
  return count;
}
void main(void)
{
    int a=123456789;
 cout< }
最后输出的结构是11

 

 2.编程写出N个无序的整数(无重复的)。。找出第K大的整数,
答案为:
#include
int BubbleSort(int a[],int N)
{
 for(int i=0;i   for(int j=i+1;j   {
   if(a[i]    {
    int temp=a[i];
    a[i]=a[j];
    a[j]=temp;
   }
  }
  return 0;
}
void main(void)
{
 int a[10]={1,3,5,2,45,36,8,6,123,56};
 BubbleSort(a,10);
 int k;
 cout<<"请输入k值:";
 cin>>k;
 for(int i=0;i<10;i++)
  cout<  cout<<"\n第k大的整数为:"<   
}
3:
堆和栈的区别?他们各自的运行方式是什么?
 静态变量,全局变量,局部变量的含义是什么?
SendMessage和PostMessage的区别是什么?
答:堆,优先级队列。fifo,栈,就是栈 filo
LRESULT SendMessage(
  HWND
hWnd     // handle of destination window
  UINT Msg      // message to send
  WPARAM wParam // first message parameter
  LPARAM lParam   // second message parameter
);
BOOL PostMessage(
  HWND
hWnd     // handle of destination window
  UINT Msg      // message to post
  WPARAM wParam // first message parameter
  LPARAM lParam   // second message parameter
);
两个函数的区别,我想你们已经看出来了吧。SendMessage函数将指定的消息发送到一个或多个窗口。此函数为指定的窗口调用窗口程序,直到窗口程序 处理完消息再返回。而函数PostMessage不同,将一个消息寄送到一个线程的消息队列后立即返回。
其他的,我就很难叙述的清楚了,要查资料的话也要自己去
4.给出一个数据结构,要求算出树的高度.
这题目是最简单的了,只要稍微有点记忆的人都应该记得。不过我却一点印象也没有,只记得要用递归。
int TreeDepth(Bintree *head)
{
 int ldepth,rdepth;
 if(head==NULL) return 0;
 else {ldepth=TreeDepth(head->lchild)+1; 
 rdepth=TreeDepth(head->rchild)+1;
 return(Max(ldepth,rdepth));
 }
}
就这么简单,最后我的时间只有5分钟了...
5.用C实现测试CPU字长的内存模式是 big_endian还是little_endian。

#include

int TestEndian()
{
 int a=123456789;//111010110111100110100010101->123456789->0x075BCD15
 int *pointer=&a;
 char *p=(char *)pointer;
 if(*p==7)
  return 0;
 else
  return 1;
}
void main()
{
 int b=TestEndian();
 if(b==0)
  cout<<"内存模式为:bigendian "<  else
  cout<<"内存模式为:littleendian "< }

阅读(590) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~