Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
又一个大水!~ ~#include <iostream> #include <stdio.h> using namespace std; int coef[9]; int ab(int n){ if(n>0) return n; return -n; } int main() { while(scanf("%d", &coef[8]) > 0){ for(int i = 7; i >= 0; i--) scanf("%d", &coef[i]); bool haveOne = false; for(int i = 8; i > 0; i--){ if(!coef[i]) continue; if(!haveOne){ if(coef[i] < 0) printf("-"); } else{ printf(" %c ", (coef[i] > 0 ? '+' : '-')); } haveOne = true; int a = ab(coef[i]); if(a!=1) printf("%d", a); printf("x"); if(i>1) printf("^%d", i); } if(!haveOne){ printf("%d\n", coef[0]); } else if(coef[0]){ printf(" %c %d\n", (coef[0] > 0 ? '+' : '-'), ab(coef[0])); } else{ printf("\n"); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator