PAT (Advanced Level) Practice 1002 A+B for Polynomials

这题目的题设就是傻逼。

保留一位小数是系数保留一位小数,指数是整数,不存在小数的情况,所以不保留。

系数是整数也要保留一位小数。

别去想什么0.04应该化为0.0,0.05化为0.1。

这个傻逼输出坑死我了。

#include 
int main()
{
	float A[1002] = { 0 };
	float B[1002] = { 0 };
	float C[1002] = { 0 };
	int count_A, count_B;
	int i;
	int location;
	float add;
	int sum=0;
	scanf("%d", &count_A);
	for (i = 0; i < count_A; i++)
	{
		scanf("%d", &location);
		scanf("%f", &add);
		A[location] = A[location] + add;
	}
	scanf("%d", &count_B);
	for (i = 0; i < count_B; i++)
	{
		scanf("%d", &location);
		scanf("%f", &add);
		B[location] = B[location] + add;
	}
	for (i = 0; i < 1001; i++)
	{
		C[i] = A[i] + B[i];
		if(C[i]!=0)
			sum++;
	}
	if (sum == 0)
		printf("0");
	else
		printf("%d", sum);
	for (i = 1000; i >=0; i--)
	{
		if (C[i] != 0)
			printf(" %d %.1f", i, C[i]);
	}
}

 

你可能感兴趣的:(PAT,PAT(Advanced))