华为笔试题:计算字符串“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 阅读(352)
评论(0) 编辑 收藏 所属分类:
C++&C