Expression
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
作为一个干部,Trt真的很累,所以从来都是上课低着头玩手机。当然Trt也有自己的主业-美工。作为项目组的得力干将,老师总是会分担很多任务给她,即使是额外的内容。项目组最近开发了一个软件-无聊。软件可以获取所有二次方程的系数,但是有天程序发生故障,只有系数,表达式全部丢失。老师哭着找到Trt,Trt很忙哭着找到Caoyu,caoyu不忙但是智商着急,哭着找到你们,作为全宇宙最聪明美丽的你们,一定不会丢下我的吧?
给你二次方程的系数,输出原有的二次方程。具体格式见样例。
Input
Output
Sample Input
5 5 5 3 0 3
Sample Output
5x^2+5x+5 3x^2+3
Author
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#include <stack>
#define maxn 10000+5
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
bool cmp(int a,int b){
return a>b;
}
int a,b,c;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(cin>>a>>b>>c)
{
if(a==0)
{
if(b==0)
{
if(c==0)
{
cout<<0<<endl;
}
else
{
cout<<c<<endl;
}
}
else
{
if(b==1)
{
if(c==0)
cout<<"x"<<endl;
else if(c>0) cout<<"x"<<"+"<<c<<endl;
else if(c<0)cout<<"x"<<c<<endl;
}
if(b==-1)
{
if(c==0)
cout<<"-x"<<endl;
else if(c>0)cout<<"-x"<<"+"<<c<<endl;
else if(c<0)cout<<"-x"<<c<<endl;
}
if(b!=1&&b!=-1)
{
if(c==0)
{
cout<<b<<"x"<<endl;
}
if(c!=0)
{
if(b>0)
{
if(c>0)cout<<b<<"x"<<"+"<<c<<endl;
else cout<<b<<"x"<<c<<endl;
}
else
{
if(c>0)cout<<b<<"x"<<"+"<<c<<endl;
else cout<<b<<"x"<<c<<endl;
}
}
}
}
}
else
{
if(a==1)cout<<"x^2";
if(a==-1)cout<<"-x^2";
if(a!=1&&a!=-1)cout<<a<<"x^2";
if(b==0)
{
if(c!=0)
{
if(c>0)cout<<"+"<<c;
else cout<<c;
}
else
{
//什么也不输出
}
}
else
{
if(b==1)
{
cout<<"+x";
if(c!=0)
{
if(c>0)cout<<"+"<<c;
else cout<<c;
}
}
if(b==-1)
{
cout<<"-x";
if(c!=0)
{
if(c>0)cout<<"+"<<c;
else cout<<c;
}
}
if(b!=-1&&b!=1)
{
if(b>0)
{
if(c!=0)
{
if(c>0)cout<<"+"<<b<<"x"<<"+"<<c;
else cout<<"+"<<b<<"x"<<c;
}
else cout<<"+"<<b<<"x";
}
else
{
if(c!=0)
{
if(c>0)cout<<b<<"x"<<"+"<<c;
else cout<<b<<"x"<<c;
}
else cout<<b<<"x";
}
}
}
cout<<endl;
}
}
return 0;
}