【PAT】2-2 一元多项式求导

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;


#define read() freopen("in.txt", "r", stdin)
#define write() freopen("out.txt", "w", stdout)
#define rep( i , a , b ) for ( int i = ( a ) ; i <  ( b ) ; ++ i )  
#define For( i , a , b ) for ( int i = ( a ) ; i <= ( b ) ; ++ i ) 
#define clr( a , x ) memset ( a , x , sizeof a )  
#define cpy( a , x ) memcpy ( a , x , sizeof a ) 
#define max(a,b) (a>b)?(a):(b)
#define LL long long 

struct daoshu
{
	int n;
	int e;
};
daoshu temp[1002];
daoshu num[1002];
int main()
{
	read(); 
    int x,y;
    int index=0,k=0;
    while(scanf("%d%d",&x,&y)!=EOF)
    {
    	temp[index].n = x;
    	temp[index++].e = y;
    }
    for (int i = 0; i < index; ++i)
    {
    	if (temp[i].e)
    	{
    		num[k].n = temp[i].n*temp[i].e;
    		num[k++].e = temp[i].e - 1;
    	}
    }
    if (k == 0)
    {
    	printf("0 0\n");
    	return 0;
    }
    for (int i = 0; i < k; ++i)
    {
    	printf("%d %d",num[i].n,num[i].e);
    	if (i-k+1)
    	{
    		printf(" ");
    	}else
    	{
    		printf("\n");
    	}
    }
    return 0;
   
}

  

posted @ 2015-03-20 02:35  Summer先生  阅读(172)  评论(0编辑  收藏  举报