Guest User

Untitled

a guest
Jul 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. int as[9];
  5.     int n;
  6. int steps[11];
  7.  
  8.     struct zeta
  9.     {
  10.         int st;
  11.         int val;
  12.     };
  13.  
  14. void mas(int step,zeta param)
  15. {
  16.  
  17.  if (step<n)
  18.  {
  19.      param.st++;
  20.      mas(step+1,param);
  21.      param.st--;
  22.      param.val*=as[step];
  23.      mas(step+1,param);
  24.  }
  25.  else
  26.  {
  27.      steps[param.st]+=param.val;
  28.  }
  29.  
  30. }
  31.  
  32. int main()
  33. {  
  34.         ifstream cin;
  35.     ofstream cout;
  36.     cin.open ("input.txt");
  37.     cout.open ("output.txt");
  38.     zeta inic;
  39.     inic.st=0;
  40.     inic.val=1;
  41.  
  42. for (int i=0;i<=10;i++) steps[i]=0;
  43.     cin >> n;
  44.     for (int i=0;i<n;i++) cin >> as[i];
  45. mas (0,inic);
  46.  
  47. for (int i=n+1;i>1;i--)
  48.     {
  49.         if (steps[i])
  50.      {
  51.            if (steps[i]==1) cout << "X^" << i ;
  52.           else
  53.               if (steps[i]==-1) cout << "-X^" << i;
  54.               else
  55.            cout << steps[i]<<"*X^" << i;
  56.            
  57.      }
  58.         if (i>0&&steps[i-1]>0&&i!=n+1) cout << "+";
  59. }
  60.      //if (steps[1]>0) cout << "+";
  61.      if (steps[1])
  62.          if (steps[1]==1)cout <<"X";
  63.          else
  64.          if (steps[1]==-1) cout <<"-X"; else cout <<steps[1]<<"*X";
  65.      if (steps[0]>0) cout << "+";
  66.      if (steps[0]) cout << steps[0];
  67. cin.close();
  68. cout.close();
  69.     return 0;
  70. }
Add Comment
Please, Sign In to add comment