Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

又一个大水!~ ~

Posted by KatrineYang at 2017-01-22 13:50:33 on Problem 1555
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator