linjinkun @ 2024-09-17 16:36:30
一切回复请 at,感谢各位大佬的帮助
by linjinkun @ 2024-09-17 16:37:54
哦,忘了发代码了
#include<bits/stdc++.h>
using namespace std;
signed main()
{
freopen("uqe.in","r",stdin);
freopen("uqe.out","w",stdout);
string n;
cin >> n;
int xishu1 = 0,xishu2 = 0,shuliang1 = 0,shuliang2 = 0;
int num = 0;
int ans1 = 0,ans2 = 0,ans3 = 0;
for(int i = 1;n[i]!='x';i++)
{
xishu1 = xishu1*10+n[i]-'0';
ans1++;
}
for(int i = 0;i<n.size();i++)
{
if(n[i] == '('&&num == 1)
{
for(int j = i+1;n[j]!='x';j++)
{
ans2++;
xishu2 = xishu2*10+n[j]-'0';
}
break;
}
else if(n[i] == '(')
{
num++;
}
}
for(int i = ans1+3;n[i]!=')';i++)
{
ans3++;
shuliang1 = shuliang1*10+n[i]-'0';
}
for(int i = ans1+ans3+ans2+7;n[i]!=')';i++)
{
shuliang2 = shuliang2*10+n[i]-'0';
}
int ercifangji = 0,yicifangji = 0,lingcifangji = 0;
ercifangji+=xishu1*xishu2;
yicifangji+=xishu1*shuliang2;
yicifangji+=shuliang1*xishu2;
lingcifangji+=shuliang1*shuliang2;
struct node
{
int x;
int y;
}cnt[10];
int k = 0;
if(ercifangji!=0)
{
cnt[++k].x = ercifangji;
cnt[k].y = 2;
}
if(yicifangji!=0)
{
cnt[++k].x = yicifangji;
cnt[k].y = 1;
}
if(lingcifangji!=0)
{
cnt[++k].x = lingcifangji;
cnt[k].y = 0;
}
for(int i = 1;i<=k;i++)
{
if(cnt[i].y == 2)
{
if(cnt[i].x == 1)
{
printf("x^2");
}
else
{
printf("%dx^2",cnt[i].x);
}
}
else if(cnt[i].y == 1)
{
if(cnt[i].x == 1)
{
printf("x");
}
else
{
printf("%dx",cnt[i].x);
}
}
else if(cnt[i].y == 0)
{
printf("%d",cnt[i].x);
}
if(i!=k)
{
printf("+");
}
}
if(ercifangji == 0)
{
if(yicifangji == 0&&lingcifangji!=0)
{
printf("\nNo");
}
else if(yicifangji == 0&&lingcifangji == 0)
{
printf("\n0");
}
else
{
if((0-lingcifangji)/yicifangji*yicifangji == 0-lingcifangji)
{
printf("\n%d",(0-lingcifangji)/yicifangji);
}
else
{
printf("\nNo");
}
}
}
else
{
if(yicifangji*yicifangji-4*ercifangji*lingcifangji<0)
{
printf("\nNo");
}
else
{
double t = double(-yicifangji+sqrt(yicifangji*yicifangji-4*ercifangji*lingcifangji))/double(2*ercifangji);
double t1 = double(-yicifangji-sqrt(yicifangji*yicifangji-4*ercifangji*lingcifangji))/double(2*ercifangji);
int s = t;
int s1 = t1;
if(s == t||s1 == t1)
{
printf("\n%d",(s == t)?s:s1);
}
else
{
printf("\nNo");
}
}
}
return 0;
}
为什么只有