http://47.104.209.207/problem/old1063
字符串处理,直接依据定义输出字符串。
1 #include <iostream> 2 #include <cstring> 3 #include <algorithm> 4 5 using namespace std; 6 7 void printAn(int n){ 8 for(int i=1;i<=n;i++){ 9 cout<<"sin("<<i; 10 if(i!=n){ 11 if(i%2!=0){ 12 cout<<"-"; 13 }else{ 14 cout<<"+"; 15 } 16 }else{ 17 for(int j=1;j<=n;j++){ 18 cout<<")"; 19 } 20 } 21 } 22 } 23 void printSn(int n){ 24 for(int i=1;i<n;i++){ 25 cout<<"("; 26 } 27 for(int i=1;i<=n;i++){ 28 if(i!=n){ 29 printAn(i); 30 cout<<"+"<<n-i+1<<")"; 31 } 32 else{ 33 printAn(i); 34 cout<<"+"<<n-i+1<<endl; 35 } 36 } 37 } 38 int main() 39 { 40 int n; 41 cin>>n; 42 printSn(n); 43 return 0; 44 }