cust 学校选拔赛

Expression

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Font: Times New Roman | Verdana | Georgia
Font Size:  

Problem Description

Caoyu的女神是Trt。
作为一个干部,Trt真的很累,所以从来都是上课低着头玩手机。当然Trt也有自己的主业-美工。作为项目组的得力干将,老师总是会分担很多任务给她,即使是额外的内容。项目组最近开发了一个软件-无聊。软件可以获取所有二次方程的系数,但是有天程序发生故障,只有系数,表达式全部丢失。老师哭着找到Trt,Trt很忙哭着找到Caoyu,caoyu不忙但是智商着急,哭着找到你们,作为全宇宙最聪明美丽的你们,一定不会丢下我的吧?
给你二次方程的系数,输出原有的二次方程。具体格式见样例。

Input

多组数据输入,每行有三个整数a,b,c(-20<=a,b,c<=20)

Output

输出表达式

Sample Input

5 5 5
3 0 3

Sample Output

5x^2+5x+5
3x^2+3

Author

caoyu01

现场坑了很久的题目。。。重写好了。。可当时又不忍心重写,今天放下心重写一遍

#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;
}



 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值