TURNING ON STREET LIGHTS


Submit solution

Points: 10
Time limit: 300.0s
Memory limit: 64K

Author:
Problem type
Allowed languages
C

Problem Statement

You are given an 8 bit binary string consisting of only 1s and 0s where 1 indicates ON and 0 indicates OFF. You need to compute the minimum number of switches that need to be toggled so as to achieve the state where every switch is active.If min_switches > 4 output should be "More than half"

Eg: 11111001 2 11000111 3 11111111 0 00001001 More than half


Comments


  • 0
    Vaibhav  commented on May 4, 2023, 7:26 p.m.

    include<stdio.h>

    int main() { int a,y,count=0; scanf("%d",&a); while(a!=0) { y=a%10; if(y==0) { count++; } a=a/10;

    }
    if(count>4)
    {
        printf("More than half");
    }
    else
    {
        printf("%d",count);
    }
    return 0;

    }