囧囧出的题……他自己都没过(一元多项式之和)

Description

今天抛抛和狗神一块去买黑板,碰到了pis大神。pis请他们吃包子,自然他们就开始不客气的吃起来。他们吃的数量可以用一个一元多项式来表示,要注意的是:他们所吃的数量,有着相同的指数,这个你懂的。(如dogdog eat 3x^2+2x and paopao eat 5x^2+x,then they eat 8x^2+3x) 用链表写

Input

第一行,输入多项式的每一项的系数与指数并以0 0为结束标志。接下来输入多项式的每一项的系数与指数并以0 0为结束标志。

Output

进行相加后的各项系数和指数.

Sample Input

4 2 1 1 0 0 7 2 1 1 0 0

Sample Output

11 2      2 1
 
 
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main()
{
int num[10000], a, b;
while( scanf( "%d%d", &a, &b )== 2 )
{
int k = 0;
memset( num, 0, sizeof(num) );
num[b] += a;
while( scanf( "%d%d", &a, &b ), a||b )
num[b] += a;
while( scanf( "%d%d", &a, &b ), a||b )
{
k++;
num[b] += a;
}
for( a = 9999; a >= 0; a-- )
{
if( num[a] )
{
printf( a == k?"%d %d":" %d %d", num[a], a );
}
}
puts( "" );
}
}
膜拜狗神……他给我的思路……
原文地址:https://www.cnblogs.com/zsj576637357/p/2381682.html