posts - 30,  comments - 28,  trackbacks - 0
华为笔试题:计算字符串“010111001100....”中‘0’和‘1’连续出现的次数。

#include<iostream>;

void main() {

   char *charArray="01000111100011100111100001";
   int max[2]    ={0,0};
   int count[2]  ={0,0};

  while(*charArray){
      
  int   index     =*charArray-'0';

  count[index]++;
  count[index^1] =0;

  if(count[index]>max[index])
        max[index]=count[index];

  charArray++;
  }
 
 std:cout<<"Max times of 0 is"<<max[0]<<std:endl;
 std:cout<<"Max times of 1 is"<<max[1]<<std:endl;
}
//~:end the codes

程序代码的艺术化,呵呵
posted on 2006-09-26 03:57 murainwood 阅读(344) 评论(0)  编辑  收藏 所属分类: C++&C

只有注册用户登录后才能发表评论。


网站导航:
 
<2006年9月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

如果真的给你一片天,你敢不敢要?

常用链接

留言簿(3)

随笔分类

随笔档案

相册

搜索

  •  

最新评论

阅读排行榜

评论排行榜