http://acm.hdu.edu.cn/showproblem.php?pid=5095
Problem Description
SVM(Support Vector Machine)is an important classification tool, which has a wide range of applications in cluster analysis, community division and so on. SVM The kernel functions used in SVM have many forms. Here we only discuss the function of the form f(x,y,z) = ax^2 + by^2 + cy^2 + dxy + eyz + fzx + gx + hy + iz + j. By introducing new variables p, q, r, u, v, w, the linearization of the function f(x,y,z) is realized by setting the correspondence x^2
<-> p, y^2
<-> q, z^2
<-> r, xy
<-> u, yz
<-> v, zx
<-> w and the function f(x,y,z) = ax^2 + by^2 + cy^2 + dxy + eyz + fzx + gx + hy + iz + j can be written as g(p,q,r,u,v,w,x,y,z) = ap + bq + cr + du + ev + fw + gx + hy + iz + j, which is a linear function with 9 variables.
Now your task is to write a program to change f into g.
Now your task is to write a program to change f into g.
Input
The input of the first line is an integer T, which is the number of test data (T<120). Then T data follows. For each data, there are 10 integer numbers on one line, which are the coefficients and constant a, b, c, d, e, f, g, h, i, j of the function f(x,y,z) = ax^2 + by^2 + cy^2 + dxy + eyz + fzx + gx + hy + iz + j.
Output
For each input function, print its correspondent linear function with 9 variables in conventional way on one line.
Sample Input
2 0 46 3 4 -5 -22 -8 -32 24 27 2 31 -5 0 0 12 0 0 -49 12
Sample Output
46q+3r+4u-5v-22w-8x-32y+24z+27 2p+31q-5r+12w-49z+12
/**
模拟,看样例就能知道它想说什么,不过有几点比较坑。
(1)前缀1不用写(当然包括-1)
(2)所有都是0,输出的是0,而不是什么都不输出
好吧,我承认我写的很乱
*/
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int a, b, c, d, e, f, g, h, i, j;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);
if(a>1)
{
printf("%dp",a);
}
else if(a==1)
{
printf("p");
}
else if(a<0)
{
if(a==-1)
printf("-p");
else
printf("%dp",a);
}
if(b==1)
{
if(a==0)
printf("q");
else
printf("+q");
}
else if(b>1)
{
if(a==0)
printf("%dq",b);
else
printf("+%dq",b);
}
else if(b<0)
{
if(b==-1)
printf("-q");
else
printf("%dq",b);
}
if(c>1)
{
if(a==0&&b==0)
printf("%dr",c);
else
printf("+%dr",c);
}
else if(c==1)
{
if(a==0&&b==0)
printf("r");
else
printf("+r");
}
else if(c<0)
{
if(c==-1)
printf("-r");
else
printf("%dr",c);
}
if(d>1)
{
if(a==0&&b==0&&c==0)
printf("%du",d);
else
printf("+%du",d);
}
else if(d==1)
{
if(a==0&&b==0&&c==0)
printf("u");
else
printf("+u");
}
else if(d<0)
{
if(d==-1)
printf("-u");
else
printf("%du",d);
}
if(e>1)
{
if(a==0&&b==0&&c==0&&d==0)
printf("%dv",e);
else
printf("+%dv",e);
}
else if(e==1)
{
if(a==0&&b==0&&c==0&&d==0)
printf("v");
else
printf("+v");
}
else if(e<0)
{
if(e==-1)
printf("-v");
else
printf("%dv",e);
}
if(f>1)
{
if(a==0&&b==0&&c==0&&d==0&&e==0)
printf("%dw",f);
else
printf("+%dw",f);
}
else if(f==1)
{
if(a==0&&b==0&&c==0&&d==0&&e==0)
printf("w");
else
printf("+w");
}
else if(f<0)
{
if(f==-1)
printf("-w");
else
printf("%dw",f);
}
if(g>1)
{
if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0)
printf("%dx",g);
else
printf("+%dx",g);
}
else if(g==1)
{
if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0)
printf("x");
else
printf("+x");
}
else if(g<0)
{
if(g==-1)
printf("-x");
else
printf("%dx",g);
}
if(h>1)
{
if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0&&g==0)
printf("%dy",h);
else
printf("+%dy",h);
}
else if(h==1)
{
if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0&&g==0)
printf("y");
else
printf("+y");
}
else if(h<0)
{
if(h==-1)
printf("-y");
else
printf("%dy",h);
}
if(i>1)
{
if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0&&g==0&&h==0)
printf("%dz",i);
else
printf("+%dz",i);
}
else if(i==1)
{
if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0&&g==0&&h==0)
printf("z");
else
printf("+z");
}
else if(i<0)
{
if(i==-1)
printf("-z");
else
printf("%dz",i);
}
if(j>0)
{
if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0&&g==0&&h==0&&i==0)
printf("%d",j);
else
printf("+%d",j);
}
else if(j<0)
{
printf("%d",j);
}
if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0&&g==0&&h==0&&i==0&&j==0)
printf("0");
printf("\n");
}
return 0;
}