English, asked by chandinichanu24, 1 month ago

All zeroes
You are given the following:
• Two integers N and K
• A string S of size N consisting of Os and 1s
You can perform the following operations on it:
• In string S, choose a substring of size K and change each 'O' into 'l' and vice versa in it.
Task
Determine whether it is possible to convert every character of the string S to 'O', by performing the described
operation, any number of times (possibly zero). If it is possible, then print 1 else 0.
Notes
• String a is a substring of string b if it is possible to choose several consecutive letters in b in such a w
that they form a.
10
• Assume 1-based indexing.
ENG
00
El 34°C ~
10-07
w​

Answers

Answered by CuteBlossomGirl
10

Answer:

can't understand the question☹☹☹☹

Answered by pruthaasl
0

Answer:

#include <iostream>

using namespace std;

void minOperation(string S, int K, int N)

{

   int min = 0;

   int i;

   for (i = 0; i < N; i++)

   {

       if (S[i] == '0' && i + K <= N)

       {

           for (int j = i; j < i + K; j++)

           {

               if (S[j] == '1')

                   S[j] = '0';

               else

                   S[j] = '1';

           }

           min++;

       }

   }

   for (i = 0; i < N; i++) {

       if (S[i] == '0')

           break;

   }

   if (i == N)

       cout << min;

   else

       cout << 0;

}

int main()

{

   string S = "00010110";

   int K = 3;

   int N = S.length();

   minOperation(S, K, N);

   return 0;

}

Explanation:

  • We declare a function called min Operation which returns the minimum number in which all the characters can be converted to 0s.
  • We use a nested structure of for and if loops.
  • In the main function, we define a string S with 1s and 0s as the characters.
  • We call the min Operation function in the main function which returns the count of the number of times the operation takes place.
  • In case it is not possible to convert the string into 0, the output printed is 0.

#SPJ3

Similar questions
Math, 9 months ago