求Debug,自己搞整式除法程序,翻车了。
  • 板块学术版
  • 楼主__lzn
  • 当前回复6
  • 已保存回复6
  • 发布时间2021/8/23 12:13
  • 上次更新2023/11/4 09:22:10
查看原帖
求Debug,自己搞整式除法程序,翻车了。
244494
__lzn楼主2021/8/23 12:13

大家可以自己运行,看输出 帮帮我CSP 2等的菜鸡谢谢您了

#include<bits\stdc++.h>
int bcs[105],cs[105],cszsmax,bcszsmax,intmplen;
char intmp[105];
using namespace std;
void input()
{
	printf("      _|                                  \n      _|    _|_|_|  _|      _|    _|_|_|  \n      _|  _|    _|  _|      _|  _|    _|  \n_|    _|  _|    _|    _|  _|    _|    _|  \n  _|_|      _|_|_|      _|        _|_|_|  \n                                          \n                                          \n                                                                                          \n  _|_|_|                _|_|    _|                                                        \n_|          _|_|      _|      _|_|_|_|  _|      _|      _|    _|_|_|  _|  _|_|    _|_|    \n  _|_|    _|    _|  _|_|_|_|    _|      _|      _|      _|  _|    _|  _|_|      _|_|_|_|  \n      _|  _|    _|    _|        _|        _|  _|  _|  _|    _|    _|  _|        _|        \n_|_|_|      _|_|      _|          _|_|      _|      _|        _|_|_|  _|          _|_|_|  \n");
	cout<<endl<<"输入格式为±(a1)x^(b1)±(a2)x^(b2)±...±(an-1)x^(bn-1)±(an)x^(bn),其中括号不用输入,括号内是变量,a是大于0的有理数,符号由±控制,b是自然数。输入应是最简多(单)项式,且必须降幂排列!常数项x的指数b为零,若有常数项,应输入...x^0!若系数a==1,应输入1x^..."<<endl<<"输入被除式。"<<endl; 
	gets(intmp);
	intmplen=strlen(intmp);
	//e.g. +5x^3-1x^2+6x^0
	bool xs=0;
	int zs=0;
	for(int i=intmplen-1;i>=0;--i)
	{
		if(intmp[i]=='^'){
			continue;
		}
		if(intmp[i]=='x')
		{
			xs=1;
			continue;
		}
		if(intmp[i]=='-'||intmp[i]=='+')
		{
			xs=0; 
			if(intmp[i]=='-')
			{
				bcs[zs]*=-1;
			}
			continue;
		}
		if(xs==1)
		{
			int _10x=1;
			for(int j=i;;--j)
			{
				if(intmp[j]>='0'&&intmp[j]<='9')
				{
					bcs[zs]+=_10x*((int)intmp[j]-48);
					_10x*=10;
				}
				else
				{
					i=j-1;
					break;
				}
			}
		}
		else
		{
			zs=0;
			int _10x=1;
			for(int j=i;;--j)
			{
				if(intmp[j]>='0'&&intmp[j]<='9')
				{
					zs+=_10x*((int)intmp[j]-48);
					_10x*=10;
				}
				else
				{
					i=j-1;
					break;
				}
			}
		}
	}
	bcszsmax=zs;
	cout<<"输入除式。"<<endl; 
	gets(intmp);
	intmplen=strlen(intmp);
	xs=0;
	zs=0;
	for(int i=intmplen-1;i>=0;--i)
	{
		if(intmp[i]=='^'){
			continue;
		}
		if(intmp[i]=='x')
		{
			xs=1;
			continue;
		}
		if(intmp[i]=='-'||intmp[i]=='+')
		{
			xs=0; 
			if(intmp[i]=='-')
			{
				bcs[zs]*=-1;
			}
			continue;
		}
		if(xs==1)
		{
			int _10x=1;
			for(int j=i;;--j)
			{
				if(intmp[j]>='0'&&intmp[j]<='9')
				{
					cs[zs]+=_10x*((int)intmp[j]-48);
					_10x*=10;
				}
				else
				{
					i=j-1;
					break;
				}
			}
		}
		else
		{
			zs=0;
			int _10x=1;
			for(int j=i;;--j)
			{
				if(intmp[j]>='0'&&intmp[j]<='9')
				{
					zs+=_10x*((int)intmp[j]-48);
					_10x*=10;
				}
				else
				{
					i=j-1;
					break;
				}
			}
		}
	}
	cszsmax=zs;
	return;
}
int main()
{
	input();
	//debug
	for(int i=bcszsmax;i>=0;--i)
	{
		cout<<bcs[i]<<" "; 
	}
	cout<<endl;
	for(int i=cszsmax;i>=0;--i)
	{
		cout<<cs[i]<<" "; 
	}
	cout<<endl;
	return 0;
} 
2021/8/23 12:13
加载中...