UVA10719- Quotient Polynomial

思路:还是推公式,可以得到a[i + 1] -= b[i] * (-k);

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

int main() {
	int k = 0, r;
	int a[10005], b[10005];
	while (scanf("%d", &k) != EOF) {
		int cnt = 0;	
		char ch;
		memset(a, 0, sizeof(a));
		memset(b, 0, sizeof(b));

		while (1) {
			scanf("%d%c", &a[cnt++], &ch);	
			if (ch == '\n')	
				break;	
		}	

		for(int i = 0; i < cnt - 1; i++){
			b[i] = a[i];
			a[i + 1] -= b[i] * (-k);		
		}
		
		printf("q(x):");
		for(int i = 0; i < cnt - 1; i++)
			printf(" %d", b[i]);	

		printf("\nr = %d\n\n", a[cnt - 1]);
	}

	return 0;
}



你可能感兴趣的:(UVA10719- Quotient Polynomial)