[JZOJ4803] [Simulation] derivative

Disclaimer: If you want to reprint, can be explained in the comments directly, thank you! https://blog.csdn.net/SSL_ZYC/article/details/91044459

Subject to the effect:

Topic links: https://jzoj.net/senior/#main/show/4803
output after the derivation polynomial polynomial.


Ideas:

** Analog is a problem ah.
with n n the same order term expansion. Fucks on the line.
Attention to detail! !


Code:

#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
typedef long long ll;

const int N=100010;
int len;
ll a,b;
char ch[N],c,f;
bool flag;

ll read(int &i)
{
	ll d=0;
	while (isdigit(ch[i]))
		d=(d<<3)+(d<<1)+ch[i]-48,i++;
	return d;
}

int main()
{
	freopen("equation.in","r",stdin);
	freopen("equation.out","w",stdout);
	scanf("%s",ch+1);
	len=strlen(ch+1);
	for (int i=1;i<=len;)
	{
		if (isdigit(ch[i])) a=read(i);
			else a=1;
		if (ch[i]>='a'&&ch[i]<='z') c=ch[i],i++;
			else
			{
				f=ch[i],i++;
				continue;
			}
		if (ch[i]=='^') i++;
		if (isdigit(ch[i])) b=read(i);
			else b=1;
		
		if (!b||!a) continue;
		if (f!='\000'&&(f=='-'||flag)) putchar(f);
		f='\000';
		flag=1;
		printf("%lld",a*b);
		if (b>1) putchar(c);
		if (b>2) putchar('^'),printf("%lld",b-1);
		if (i<=len) f=ch[i],i++;
	}
	if (!flag) putchar(48);
	return 0;
}

Guess you like

Origin blog.csdn.net/SSL_ZYC/article/details/91044459