40分求助
查看原帖
40分求助
1372296
Chorsty楼主2025/1/16 16:39

40分求助

#include <bits/stdc++.h>
using namespace std;

int main()
{
    bool flag = 0 ,f=1;
	int n ,x;
    cin >> n;
    for (int i=0 ,j=n;i<=n;i++ ,j--)
    {
    	cin >> x;
    	if (x == 0) continue;
    	if (j == 0)
    	{
    		if (x > 0 && !f) cout << '+';
    		if (x < 0 && !f) cout << '-';
    		cout << x;
    		if (j != 1 && j != 0) cout << "^" << j;
    		continue;
		}
    	if (x > 0 && f){
    		f = 0;
			if (x != 1) cout << x;
    		cout << "x^";
    		if (j != 1) cout << j;
    		continue;
		}
		else if (x < 0 && f){
			f = 0;
			if (x != 1) cout << x;
			cout << "x^" << j;
			continue;
		}
		
    	if (x < 0) flag = 1;
    	else flag = 0;
    	
    	x = abs(x);
    	if (flag == 1) cout << '-';
    	else cout << '+';
    	
    	if (x == 1) cout << "x";
    	else cout << x << "x";
    	if (j != 1 && j != 0) cout << "^" << j;
    	if (flag == 1) flag = 0;
    	else flag = 1;
	}
	return 0;
}
2025/1/16 16:39
加载中...