Advertisement
nihalshahria

392.cpp

Apr 7th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.05 KB | None | 0 0
  1. /*
  2.           _____       __   __   __      __                  __
  3.          |     \     |  | |  | |  |    |  |       /\       |  |
  4.          |  |\  \    |  | |  | |  |    |  |      /  \      |  |
  5.          |  | \  \   |  | |  | |  |____|  |     / /\ \     |  |
  6.          |  |  \  \  |  | |  | |   ____   |    / /__\ \    |  |
  7.          |  |   \  \ |  | |  | |  |    |  |   / ______ \   |  |
  8.          |  |    \  \|  | |  | |  |    |  |  / /      \ \  |  |_________
  9.          |__|     \_____| |__| |__|    |__| /_/        \_\ |____________|
  10. */
  11. #include <bits/stdc++.h>
  12. #define sf(a)               scanf("%d",&a)
  13. #define sfl(a)              scanf("%lld",&a)
  14. #define sff(a,b)            scanf("%d %d",&a,&b)
  15. #define sffl(a,b)           scanf("%lld %lld",&a,&b)
  16. #define sfff(a,b,c)         scanf("%d %d %d",&a,&b,&c)
  17. #define sfffl(a,b,c)        scanf("%lld %lld %lld",&a,&b,&c)
  18. #define sffff(a,b,c,d)      scanf("%d %d %d %d",&a,&b,&c,&d)
  19. #define sffffl(a,b,c,d)     scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
  20. #define sfffff(a,b,c,d,e)   scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
  21. #define sfffffl(a,b,c,d,e)  scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
  22. #define MEM(a,b)            memset(a, (b), sizeof(a))
  23. #define sfc(a)              scanf("%c",&a)
  24. #define pb(a)               push_back(a)
  25. #define X                   first
  26. #define Y                   second
  27. #define sz(x)               x.size()
  28. #define pii                 pair<int,int>
  29. #define pli                 pair<long long int,int>
  30. #define mp(a,b)             make_pair(a,b)
  31. #define fr(i,x,n)           for(int i=x;i<n;i++)
  32. #define rfr(i,x,n)          for(int i=x;i>n;i--)
  33. #define LCM(a, b)           ((a)*((b)/GCD(a,b)))
  34. template<typename T>T Abs(T a) {return (a < 0 ? -a : a);}
  35. template<typename T>T MAX(T a, T b) {return (a > b ? a : b);}
  36. template<typename T>T MIN(T a, T b) {return (a < b ? a : b);}
  37. template<typename T>T GCD(T a, T b) {if (b == 0)return a; return GCD(b, a % b);}
  38. template<typename T>inline void read(T &x) {
  39.     T f = 1; char c; x = 0;
  40.     for (c = getchar(); c < '0' || c > '9'; c = getchar())if (c == '-')f = -1;
  41.     for (; c >= '0' && c <= '9'; c = getchar())x = x * 10 + c - '0';
  42.     x *= f;
  43. }
  44. using fl = float;
  45. using db = double;
  46. using ll = long long;
  47. using ull = unsigned long long;
  48. const int mx = 1000005;
  49. const int inf = 99999999;
  50. const int intlim = 2147483648;
  51. const db PI = acos(-1); //3.14159265358979323846264338328
  52. /*------------------------------Graph Moves----------------------------*/
  53. //const int fx[]={+1,-1,+0,+0};
  54. //const int fy[]={+0,+0,+1,-1};
  55. //const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};           // Kings Move
  56. //const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};          // Kings Move
  57. //const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
  58. //const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
  59. /*---------------------------------------------------------------------*/
  60. using namespace std;
  61. int main() {
  62.     int a[10];
  63.     while (~sf(a[9])) {
  64.         for (int i = 8; i >= 1; --i)sf(a[i]);
  65.         string str = "";
  66.         int f = 0;
  67.         for (int i = 9; i > 1; --i){
  68.             if (f == 0 && a[i]) {
  69.                 if (a[i] < 0)str += "-";
  70.                 f++;
  71.                 if (a[i] != 1 && a[i] != -1)str += to_string(abs(a[i]));
  72.                 if (i != 2)str += "x^";
  73.                 else str += "x";
  74.                 if (i != 2)str += to_string(i - 1);
  75.             }
  76.             else if (a[i]) {
  77.                 if (a[i] < 0) str += " - ";
  78.                 else str += " + ";
  79.                 if (a[i] != 1 && a[i] != -1)str += to_string(abs(a[i]));
  80.                 if (i != 2)str += "x^";
  81.                 else str += "x";
  82.                 if (i != 2)str += to_string(i - 1);
  83.                 f++;
  84.             }
  85.         }
  86.         if (a[1] != 0) {
  87.             if (f == 0) {
  88.                 if (a[1] < 0)
  89.                     str += "-";
  90.             }
  91.             else {
  92.                 if (a[1] < 0)
  93.                     str += " - ";
  94.                 else str += " + ";
  95.             }
  96.             str += to_string(abs(a[1]));
  97.             f++;
  98.         }
  99.         if (f == 0)str += "0";
  100.         cout << str << endl;
  101.     }
  102.     return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement