15,923,142 members
See more:
Python
```T = int(input())

while T > 0:
n = int(input())
X = input().split()
A = [1]*n

for i in range(n - 2, -1, -1):
if X[i] == '0':
A[i] = A[i + 1]
elif X[i] == '1':
A[i] = 1
if A[i + 1] == 1:
l = i + 1
A[l] += 1
while l < n - 1:
if X[l] == '0':
A[l + 1] += 1
elif X[l] == '1' and A[l + 1] <= A[l]:
A[l + 1] += 1
else:
break
l += 1
else:
A[i] = A[i + 1] + 1

print(' '.join(map(str, A)))
T -= 1```

What I have tried:

convert this program to c++ program
Posted
Updated 29-Jul-23 2:56am
v2
Patrice T 25-Mar-21 2:04am
lol
[no name] 25-Mar-21 2:14am
whats so funny
Rick York 25-Mar-21 4:10am
Correction : you have tried nothing except for demanding that someone convert this for you. You don't even have the decency to ask nicely.

I am not going to be nice about it - NO!!! Do it yourself.

## Solution 1

You need to do Code Rewrite[^]. Learn both languages & try out syntaxes of both languages.

Even Code conversion services can't give 100% converted code due to differences of syntax, libraries & etc.,

Learn programming which is fun half of times.

## Solution 2

This is not a code conversion service: we are not here to translate code for you.
Even if we did, what you would end up with would not be "good code" in the target language – they are based on very different frameworks, and what makes something work in one language does not always "translate" directly into another.
So what you end up with is very poor code, that is difficult if not impossible to maintain, that can’t be upgraded nicely, and that will cause you immense headaches if the original is changed. And it’ll be a nightmare to debug if it doesn’t work "straight out of the box".
Instead, use the source code as a specification for a new app written in and for the target language / framework and write it from scratch using the original as a "template". You will get a much, much better result that will save you a lot of time in the long run.