Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.0 kB
3
Indexable
Never
#include<stdio.h>
#include<ctype.h>
#include<stack>
#include<queue>
#include<string.h>
#include<iostream>
using namespace std;

char ary[100000];

int main(){
    while(scanf("%[^\n]",ary)!=EOF){
        queue<char> alphaQueue;
        stack<int> numStack;
        int len=strlen(ary);
        for(int i=0;i<len;i++){
            if(isdigit(ary[i])){
                numStack.push(ary[i]);
            }
        }

        int i,j;
        for(i=0;i<len;i++){
            if(isdigit(ary[i])){
                j=i-1;
                while(!alphaQueue.empty()){
                    ary[j--]=alphaQueue.front();
                    alphaQueue.pop();
                }
                ary[i]=numStack.top();
                numStack.pop();
            }
            else if(isalpha(ary[i])){
                alphaQueue.push(ary[i]);
            }
        }

        j=i-1;
        while(!alphaQueue.empty()){
            ary[j--]=alphaQueue.front();
            alphaQueue.pop();
        }
        
        puts(ary);
        scanf("\n");
    }
}