View Code of Problem 11

#include <iostream>
#include<string>
using namespace std;
int main() {
	int n;int k = 0;
	while (cin >> n && n != 0) {
		string a;
		cout << "Case #" << k+ 1 << ":" << endl;
		for (int m=0; m < n; m++)
		{
			if(m==0)getline(cin, a);
			getline(cin, a);
			int b[6] = {0};
			for (int i = 0; i < a.size(); i++)
			{
				if (a[i] == 'X') {
					b[0]+= a[i - 2]-'0';
					b[1] = a[i + 2] - '0';
				}
				if (a[i] == 'Y') {
					b[2]+= a[i - 2] - '0';
					b[3] = a[i + 2] - '0';
				}
				if (a[i] == 'Z') {
					b[4]+= a[i - 2] - '0';
					b[5] = a[i + 2] - '0';
				}
			}
			for (int i = 0; i < 6; i=i+2)//求导
			{
				if (b[i + 1] != 0) {
					b[i] = b[i] * b[i + 1];
					b[i + 1]--;
				}
				
			}
			
			for (int i = 0; i < 6; i=i+2)
			{//b[i]为系数
				if (b[i]!=0&&b[i+1]!=0) {
					cout << b[i] << " ";
					cout << "* ";
					if (i == 0)cout << "X ";
					if (i == 2)cout << "Y ";
					if (i == 4)cout << "Z ";
					cout << "^ ";
					cout << b[i+1]<<" ";
					if (i == 0&&(b[i+2]!=0||b[i+4]!=0))cout << "+ ";
					if(i == 2 && b[i + 2] != 0)cout << "+ ";
					if(i==4) cout << endl;
				}
				if (b[i] != 0 && b[i + 1] == 0) {
					cout << b[i] << " ";
					if (i == 0 && b[i + 2] != 0 && b[i + 4] != 0)cout << "+ ";
					if (i == 2 && b[i + 2] != 0)cout << "+ ";
					if (i == 4) cout << endl;
				}
				if (b[i] == 0 && b[i + 1] == 0) {
				
					if (i == 4) cout << endl;
				}
			}
		}
		k++;
	}
}

Double click to view unformatted code.


Back to problem 11