Demo entry 5292741

bits equalizer

   

Submitted by anonymous on Jun 14, 2016 at 18:54
Language: C++. Code size: 826 Bytes.

#include <cstdio>
#include <cstring>

int main() {

   char S[105] = {};
   char T[105] = {};
   int C;

   scanf("%d", &C);

   for (int ncase = 1; ncase <= C; ncase++) {
      scanf("%s%s", S, T);

      int Sones = 0, Szeros = 0, Sqs = 0, Tones = 0;

      for (int i = 0; i < strlen(S); i++) {
         if (S[i] != T[i]) {
            if (S[i] == '0') {
               Szeros++; 
               Tones++;
            } else if (S[i] == '1') {
               Sones++;
            } else { //S[i] == '?'
               Sqs++;
               if (T[i] == '1') Tones++;
            }
         }
      }

      int steps = -1;
      if (Sones <= Tones) {
         steps = Sqs + (Sones < Szeros ? Szeros : Sones); 
      }

      printf("Case %d: %d\n", ncase, steps);
   }

   return 0;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).