Advertisement
silentkiler029

codeforces-1342-B

Apr 27th, 2020
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. ///BISMILLAHIR-RAHMANIR-RAHIM
  2. #include <stdio.h>
  3. #include <string.h>
  4. int main()
  5. {
  6.     int test;
  7.     scanf("%d", &test);
  8.  
  9.     char t[105], s[105];
  10.     int i, len, flag, j;
  11.  
  12.     while(test--){
  13.         scanf("%s", &t);
  14.         flag = 0;
  15.         len = strlen(t);
  16.         for(i = 1; i < len; i++){
  17.             if(t[i] != t[0]){
  18.                 flag = 1;
  19.                 break;
  20.             }
  21.         }
  22.         if(flag){
  23.             s[0] = t[0];
  24.             for(i = 1, j= 1; i < len; i++){
  25.                 if(t[i] == t[i - 1]){
  26.                     if(t[i] == '0') s[j] = '1';
  27.                     else s[j] = '0';
  28.                     j++;
  29.                     s[j] = t[i];
  30.                     j++;
  31.                 }
  32.                 else{
  33.                     s[j] = t[i];
  34.                     j++;
  35.                 }
  36.             }
  37.             s[j] = '\0';
  38.             printf("%s\n", s);
  39.         }
  40.         else{
  41.             printf("%s\n", t);
  42.         }
  43.     }
  44.  
  45.  
  46.     return 0;
  47. }
  48. ///ALHAMDULILLAH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement