1sting hdu 1865(模拟)

http://acm.hdu.edu.cn/showproblem.php?pid=1865

分析:(1)当全部为0时输出0;

      (2)当要输出字母的前面数字为1时,注意只能输出字母(-1x ——  -x  ||  1x ——— x),由于最后一项是不带字母的,所以当它为(-)1,还理应            输出(-)1。

#include <stdio.h>
#include <string.h>
#include <math.h>
#define maxn 300
char s[10]={'p','q','r','u','v','w','x','y','z'};
int a[15];

int main()
{
    int T, flag;

    scanf("%d", &T);

    while(T --)
    {
        flag = 0;

       for(int i=0; i<10; i++)
         scanf("%d", &a[i]);

         int ans = 0;
         for(int i=0; i<10; i++)
         {
             if(!a[i])
                continue;

             if(ans && a[i]>0) printf("+");
                flag = 1;
                 ans = a[i];
                 if(fabs(a[i])>1 && i!=9)
                 printf("%d",a[i]);
                 else if(a[i]<0 && i!=9)
                    printf("-");
                 else  if(i==9)
                    printf("%d", a[i]);

                 if(i!=9) printf("%c",s[i]);

         }
         if(!flag) printf("0
");
         else printf("
");
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/daydayupacm/p/5736947.html