華為筆試題:計算字符串“010111001100....”中‘0’和‘1’連續(xù)出現(xiàn)的次數(shù)。
#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
程序代碼的藝術(shù)化,呵呵
posted on 2006-09-26 03:57
murainwood 閱讀(362)
評論(0) 編輯 收藏 所屬分類:
C++&C