a = int(input())
for i in range(a):
b = input()
c = 0
d = True
e = 0
f = False
g = False
h = '\''
for j in b:
if j == '#' and not f:
g = True
break
elif j != ' ':
if d:
print(' ' * c, end='')
elif c > 0:
print(' ', end='')
c = 0
print(j, end='')
if(j == '\"' or j == '\'') and e % 2 == 0:
if f and j == h:
f = False
else:
f = True
h = j
if f:
d = True
else:
d = False
if j == '\\':
e += 1
else:
e = 0
else:
c += 1
r = j == ' '
if g and c > 1:
print(' ', end='')
if i < a - 1:
print()
1
Объяснение:
Так как язык не указан, приведу пример на SWI-Prolog.
Код:
read_int(Int) :- read(Int), integer(Int).split_int_by_numbers(0, []) :- !.split_int_by_numbers(N, [Number|Ints]) :- Number is mod(N, 10), RestN is div(N, 10), split_int_by_numbers(RestN, Ints).test_to_div(_, []).test_to_div(N, [Number|Ints]) :- mod(N, Number) =:= 0, test_to_div(N, Ints). test(Int) :- split_int_by_numbers(Int, Numbers), test_to_div(Int, Numbers), write(Int), write(" - Yes!"), nl.test(Int) :- write(Int), write(" - No!"), nl.?- read_int(Int), test(Int).