1 #include <bits/stdc++.h> 2 using namespace std; 3 /* 4 an就先输出一个sin(+数字 5 如果数字没到n的话,数字是奇数就加减号,偶数就加加号 6 到n的话,输出n个括号 7 sn要先输出n-1个括号 8 然后调用an 9 然后+数字 10 数字是从n到1 11 数字没到1·的话,就接括号 12 到1的话,就啥也不接。 13 */ 14 void an(int n) { 15 for (int i = 1; i <= n; i++) { 16 cout << "sin(" << i; 17 if (i != n) { 18 if (i % 2 == 1) { 19 cout << "-"; 20 } else { 21 cout << "+"; 22 } 23 } else { 24 for (int i = 1; i <= n; i++) { 25 cout << ")"; 26 } 27 } 28 } 29 } 30 void sn(int n) { 31 for (int i = 1; i < n; i++) { 32 cout << "("; 33 } 34 for (int i = 1; i <= n; i++) { 35 an(i); 36 cout << "+" << n + 1 - i; 37 if (i != n) { 38 cout << ")"; 39 } 40 } 41 } 42 int main() { 43 int n; 44 cin >> n; 45 sn(n); 46 cout << endl; 47 return 0; 48 }
原文:https://www.cnblogs.com/fx1998/p/12807073.html