Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- int as[9];
- int n;
- int steps[11];
- struct zeta
- {
- int st;
- int val;
- };
- void mas(int step,zeta param)
- {
- if (step<n)
- {
- param.st++;
- mas(step+1,param);
- param.st--;
- param.val*=as[step];
- mas(step+1,param);
- }
- else
- {
- steps[param.st]+=param.val;
- }
- }
- int main()
- {
- ifstream cin;
- ofstream cout;
- cin.open ("input.txt");
- cout.open ("output.txt");
- zeta inic;
- inic.st=0;
- inic.val=1;
- for (int i=0;i<=10;i++) steps[i]=0;
- cin >> n;
- for (int i=0;i<n;i++) cin >> as[i];
- mas (0,inic);
- for (int i=n+1;i>1;i--)
- {
- if (steps[i])
- {
- if (steps[i]==1) cout << "X^" << i ;
- else
- if (steps[i]==-1) cout << "-X^" << i;
- else
- cout << steps[i]<<"*X^" << i;
- }
- if (i>0&&steps[i-1]>0&&i!=n+1) cout << "+";
- }
- //if (steps[1]>0) cout << "+";
- if (steps[1])
- if (steps[1]==1)cout <<"X";
- else
- if (steps[1]==-1) cout <<"-X"; else cout <<steps[1]<<"*X";
- if (steps[0]>0) cout << "+";
- if (steps[0]) cout << steps[0];
- cin.close();
- cout.close();
- return 0;
- }
Add Comment
Please, Sign In to add comment