#include <stdio.h>
#include <stdlib.h>
#define MaxSize 100000
//定义栈
struct SqStack{
int top;
char data[MaxSize];
};
//初始化栈
void InitStack(struct SqStack *S){
S->top = -1;
}
//判断栈空
int EmptyStack(struct SqStack S){
if(S.top == -1){
return 1;
}
else{
return 0;
}
}
//压栈
int Push(struct SqStack *S, char c){
if(S->top == MaxSize - 1){
return 0;
}
S->top ++;
S->data[S->top] = c;
return 1;
}
//弹栈
int Pop(struct SqStack *S, char *c){
if(S->top == -1){
return 0;
}
*c = S->data[S->top];
S->top--;
return 1;
}
int main() {
int T;
scanf("%d\n",&T);
//创建二维数组存储字符串
char **s = (char **)malloc(sizeof(char *) * T);
if(s == NULL){
printf("Fail Malloc!\n");
return -1;
}
for(int i = 0; i < T; i ++){
s[i] = (char *)malloc(sizeof(char) * 100000);
if(s[i] == NULL){
printf("Fail Malloc!\n");
return -1;
}
//读取字符串
scanf("%s\n",s[i]);
}
for(int i = 0; i < T; i ++){
struct SqStack S;//定义栈
InitStack(&S);//初始化栈
for(int j = 0; j < MaxSize && s[i][j] != '\0'; j ++){//扫描字符串,反应剩余物全部压栈
char c;
char a = s[i][j];//a作为与栈中弹出的c反应的数,初始化为s[i][j]
while(1){//一直循环
int r = Pop(&S, &c);//弹栈
if(r == 0){//栈空则将a压栈,并跳出循环
Push(&S,a);
break;
}
else{
if(c == 'o'){
if(a == 'o'){
a = 'O';
}
else{
Push(&S,'o');
Push(&S,'O');
break;
}
}
else{
if(a == 'o'){
Push(&S,'O');
Push(&S,'o');
break;
}
else{
break;
}
}
}
}
}
//将栈S中的元素按照进入顺序打印,需要借助另一个栈S2
struct SqStack S2;
InitStack(&S2);
while(!EmptyStack(S)){
char c2;
Pop(&S, &c2);
Push(&S2, c2);
}
while(!EmptyStack(S2)){//输出S2中的元素并打印
char c3;
Pop(&S2,&c3);
printf("%c",c3);
}
printf("\n");//换行
}
free(s);
return 0;
}