artemgf

Танцы синуса

Apr 16th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string>
  4. #include <math.h>
  5. #include <algorithm>
  6. #include <vector>
  7. #include <set>
  8. #include <sstream>
  9.  
  10. using namespace std;
  11.  
  12. string convertInt(int number)
  13. {
  14.     stringstream ss;
  15.     ss << number;
  16.     return ss.str();
  17. }
  18.  
  19. string A(int n)
  20. {
  21.     string s="";
  22.     for (int i = 1; i <= n; i++)
  23.     {
  24.         string prom = convertInt(i);
  25.         if (i % 2 != 0)
  26.         {
  27.             s += "sin(";
  28.             s += prom;
  29.             if(i!=n)
  30.             s += "-";
  31.         }
  32.         else
  33.         {
  34.             s += "sin(";
  35.             s += prom;
  36.             if (i != n)
  37.             s += "+";
  38.         }
  39.     }
  40.     for (int i = 1; i <= n; i++)
  41.         s += ")";
  42.     return s;
  43. }
  44.  
  45.  
  46. string S(int n)
  47. {
  48.     string res="";
  49.     for (int i = 1; i <= n-1; i++)
  50.         res += "(";
  51.     for (int i = n; i >=2; i--)
  52.     {
  53.         string prom = convertInt(i);
  54.         res += A(n - i + 1);
  55.         res += "+";
  56.         res += prom;
  57.         res += ")";
  58.     }
  59.     res += A(n);
  60.     res += "+1";
  61.     return res;
  62. }
  63.  
  64. int main()
  65. {
  66.     int n;
  67.      
  68.     cin >> n;
  69.  
  70.     cout << S(n);
  71.  
  72.     _getch();
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment