UVA Solution 372 - WhatFix Notation - Solution in C, C++ | Volume 3 - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Friday, May 5, 2017

UVA Solution 372 - WhatFix Notation - Solution in C, C++ | Volume 3

UVA Solution 372 - WhatFix Notation - Solution in C, C++ | Volume 3


UVA Online Judge Solution 372 - WhatFix Notation | Volume 3
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=308

Problem Name: 372 - WhatFix Notation
Problem Number : UVA - 372 - WhatFix Notation
Online Judge : UVA Online Judge Solution
Volume: 3
Solution Language : C, C plus plus

UVA Solution 372 - WhatFix Notation - Solution in C, C++ | Volume 3

UVA Solution 372 - WhatFix Notation Code in C, CPP:


#include <stdio.h>
char infix[105], prefix[105];
int idx;
void dfs(int l, int r) {
    if(l > r)   return;
    char p = prefix[idx], i;
    idx++;
    for(i = l; i <= r; i++)
        if(infix[i] == p)
            break;
    dfs(l, i-1);
    dfs(i+1, r);
    printf(" %c", p);
}
int main() {
    while(gets(infix)) {
        gets(prefix);
        int i, j;
        for(i = 0, j = 0; infix[i]; i++) {
            if(infix[i] != ' ')
                infix[j++] = infix[i];
        }
        infix[j] = '\0';
        for(i = 0, j = 0; prefix[i]; i++) {
            if(prefix[i] != ' ')
                prefix[j++] = prefix[i];
        }
        prefix[j] = '\0';
        printf("INFIX   =>");
        for(i = 0; infix[i]; i++)
            printf(" %c", infix[i]);
        puts("");
        printf("PREFIX  =>");
        for(i = 0; prefix[i]; i++)
            printf(" %c", prefix[i]);
        puts("");
        printf("POSTFIX =>");
        idx = 0;
        dfs(0, j-1);
        puts("");
    }
    return 0;
}

No comments:

Post a Comment