python
# -*- coding:utf-8 -*-
class Solution:
def trans(self, s, n):
# write code here
res = [' '] * n
i, j = n-1, 0
stack = []
while i >= 0:
while i >= 0 and s[i].isalpha():
if s[i].isupper():
stack.append(s[i].lower())
else:
stack.append(s[i].upper())
i -= 1
while stack:
res[j] = stack.pop()
j += 1
while i >= 0 and s[i] == ' ':
i -= 1
j += 1
return ''.join(res)