如下:
#include<iostream>
#include<string>
using namespace std;
string An(int n);
int main() {
int n,i;
string Sn = "",temp,pt = "0";
cin >> n;
for (i = 0; i < n; i++) {
if (i == n - 1) {
Sn = Sn + An(i+1) + "+" + "1";
break;
}
pt = "0";
pt[0] = pt[0] + (n - i);
Sn = "(" + Sn + An(i+1) +"+"+ pt+")";
}
cout << Sn << endl;
return 0;
}
//递归不可行
string An(int n) {
string temp = "sin",ret = "",pt = "0";
for (int i = n; i >= 1; i--) {
if (i == n) {
pt = "0";
pt[0] = pt[0] + n;
ret = temp + "(" + pt + ")";
continue;
}
if (i == 1) {
ret = temp + "(1-" + ret + ")";
break;;
}
if (i % 2 == 0) {
pt = "0";
pt[0] = pt[0] + i;
ret = temp + "(" + pt + "+" + ret + ")";
}
else {
pt = "0";
pt[0] = pt[0] + i;
ret = temp + "(" + pt + "-" + ret + ")";
}
}
return ret;
}