UVA Solution 392 - Polynomial Showdown - 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 392 - Polynomial Showdown - Solution in C, C++ | Volume 3

UVA Solution 392 - Polynomial Showdown - Solution in C, C++ | Volume 3


UVA Online Judge Solution 392 - Polynomial Showdown | Volume 3
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=328

Problem Name: 392 - Polynomial Showdown
Problem Number : UVA - 392 - Polynomial Showdown
Online Judge : UVA Online Judge Solution
Volume: 3
Solution Language : C, C plus plus

UVA Solution 392 - Polynomial Showdown - Solution in C, C++ | Volume 3


UVA Solution 392 - Polynomial Showdown Code in C, CPP:


#include <stdio.h>
#include <stdlib.h>

int main() {
    int p[9], i, j;
    while(scanf("%d", &p[8]) == 1) {
        for(i = 7; i >= 0; i--)
            scanf("%d", &p[i]);
        j = 8;
        while(!p[j] && j >= 0)    j--;
        int flag = 0;
        if(j == -1)
            putchar('0');
        for(i = j; i >= 0; i--) {
            if(p[i]) {
                if(flag) {
                    putchar(' ');
                    if(p[i] > 0)
                        putchar('+');
                    else
                        putchar('-');
                    putchar(' ');
                } else {
                    if(p[i] < 0)
                        putchar('-');
                    flag = 1;
                }
                if(i) {
                    if(abs(p[i]) != 1)
                        printf("%d", abs(p[i]));
                    putchar('x');
                    if(i != 1)
                        printf("^%d", i);
                }
                else {
                    printf("%d", abs(p[i]));
                }
            }
        }
        puts("");
    }
    return 0;
}

No comments:

Post a Comment