Photolog

Through the Looking-Glass
2010-10-12: Through the Looking-Glass
My radio speaks is binary!
2010-10-10: My radio speaks is binary!
Gigaminx: (present for my birthday)
2010-09-16: Gigaminx: (present for my birthday)
Trini on bike
2010-09-05: Trini on bike
Valporquero
2010-08-28: Valporquero
My new bike!
2010-08-22: My new bike!
Mario and Ana's wedding
2010-08-13: Mario and Ana's wedding
Canyoning in Guara
2010-08-07: Canyoning in Guara
Trini and Mari in Marbella
2010-08-05: Trini and Mari in Marbella
Trini and Chelo in Tabarca
2010-08-03: Trini and Chelo in Tabarca
Valid XHTML 1.1
Log in
Back to list of problems

Polynomial Showdown

392.c

/* Polynomial Showdown */

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

int main(void)
{
	int i;
	int d[9];


	while(scanf("%d %d %d %d %d %d %d %d %d",
				&d[8], &d[7], &d[6], &d[5],
				&d[4], &d[3], &d[2], &d[1], &d[0])==9) {
		int first=1;
		for(i=8; i>=0; i--) {
			if (d[i]) {
				if (first) {
					first=0;
				} else {
					if (d[i]>0) {
						printf(" + ");
					} else {
						printf(" - ");
						d[i] = -d[i];
					}
				}
				if (i>0 && d[i]==-1) {
					printf("-");
				} else if (i==0 || d[i]!=1) {
					printf("%d",d[i]);
				}
				if (i) {
					printf("x");
					if (i>1) {
						printf("^%d",i);
					}
				}
			} else if (first && i==0) {
				printf("0");
			}
		}
		printf("\n");
	}
	exit(0);
}