Advertisement
Infernale

Zero One

Oct 13th, 2018
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int countBits(char s[], int length, char target){
  4.     int maxCount=0, tempCount=0;
  5.     for(int i=0;i<length;i++){
  6.         if(s[i]==target){
  7.             tempCount++;
  8.         }else{
  9.             tempCount = 0;
  10.         }
  11.         if(tempCount>maxCount){
  12.             maxCount = tempCount;
  13.         }
  14.     }
  15.     return maxCount;
  16. }
  17.  
  18. int main(){
  19.     char nums[100005];
  20.     int zCount,oCount,zMax,oMax,length,tc;
  21.     scanf("%d", &tc);
  22.     for(int i=1;i<=tc;i++){
  23.         zCount=0, oCount=0;
  24.         scanf("%d", &length);
  25.         scanf("%s", nums);
  26.         printf("Case #%d:", i);        
  27.         zMax = countBits(nums, length, '0');
  28.         oMax = countBits(nums, length, '1');
  29.         (zMax>oMax)?printf(" 0 %d\n",zMax):printf(" 1 %d\n",oMax);
  30.     }
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement