Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. chars = ['a','b','c']
  2. inp = int(input())
  3. for x in range(inp):
  4.     used = False
  5.     output = []
  6.     array = [a for a in input()]
  7.  
  8.     for pointer in range(len(array)-1):
  9.  
  10.         if array[pointer] == array[pointer+1] and array[pointer] != '?':
  11.             print(-1)
  12.             used = True
  13.             break
  14.  
  15.         if array[pointer] != '?':
  16.             output.append(array[pointer])
  17.             continue
  18.  
  19.         for char in chars:
  20.             if pointer == 0:
  21.                 if array[pointer+1] != char:
  22.                     output.append(char)
  23.                     break
  24.             else:
  25.                 if output[pointer-1] != char and array[pointer+1] != char:
  26.                     output.append(char)
  27.                     break
  28.  
  29.  
  30.     if used == False:
  31.         if len(array) != len(output):
  32.             if output[-1] == 'a' and array[-1] == '?':
  33.                 output.append('b')
  34.             elif output[-1] == 'b' and array[-1] == '?':
  35.                 output.append('a')
  36.             elif output[-1] == 'c' and array[-1] == '?':
  37.                 output.append('a')
  38.             else:
  39.                 output.append(array[-1])
  40.         print(''.join(output))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement