Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int countBits(char s[], int length, char target){
- int maxCount=0, tempCount=0;
- for(int i=0;i<length;i++){
- if(s[i]==target){
- tempCount++;
- }else{
- tempCount = 0;
- }
- if(tempCount>maxCount){
- maxCount = tempCount;
- }
- }
- return maxCount;
- }
- int main(){
- char nums[100005];
- int zCount,oCount,zMax,oMax,length,tc;
- scanf("%d", &tc);
- for(int i=1;i<=tc;i++){
- zCount=0, oCount=0;
- scanf("%d", &length);
- scanf("%s", nums);
- printf("Case #%d:", i);
- zMax = countBits(nums, length, '0');
- oMax = countBits(nums, length, '1');
- (zMax>oMax)?printf(" 0 %d\n",zMax):printf(" 1 %d\n",oMax);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement