#include #include #include #include #include using namespace std; #define MAX 1000 class BigInt { int a[MAX], d; void __kopy(const BigInt & r) { d = r.d; for (int i = d; i < MAX; i++) a[i] = r.a[i]; } public: BigInt(int x=0) { d = MAX-1; do { a[d] = x % 10; x /= 10; d--; } while(x); d++; } BigInt(char *s) { d = MAX; for (int i = 0; i < strlen(s); i++) { a[--d] = s[i] - '0'; } } BigInt(const BigInt & r) { __kopy(r); } BigInt & operator = (const BigInt & r) { if (&r != this) { __kopy(r); } return *this; } BigInt operator + (const BigInt & r) { BigInt c; int fa, fb, fc; fc = 0; int m = r.d = m-1; i--) { fa = i < d ? 0 : a[i]; fb = i < r.d ? 0 : r.a[i]; c.a[i] = fa + fb + fc; fc = c.a[i] / 10; c.a[i] %= 10; } c.d = m-1; if (c.a[c.d]==0) c.d ++ ; return c; } void print(const char * addage="") const { for (int i = d; i < MAX; i++) printf("%d", a[i]); printf("%s", addage); } void shift(int how) { if (a[MAX-1] == 0 && d == MAX-1) { return; } for (int i = d - how; i < MAX; i++) { if (i + how >= MAX) a[i] = 0; else a[i] = a[i + how]; } d -= how; } void muldig(int dig) { if (dig == 0) { d = MAX-1; a[d] = 0; } int carry = 0; for (int i = MAX-1; i >= d; i--) { a[i] = a[i]*dig+carry; carry = a[i]/ 10; a[i] %= 10; } if (carry) { a[--d] = carry; } } BigInt operator * (const BigInt & r) { BigInt c, ac; for (int i = MAX-1; i>= d; i--) { c = r; c.muldig(a[i]); c.shift(MAX-1-i); ac = ac + c; } return ac; } bool operator == (const BigInt &r) const { if (d != r.d) return false; for (int i = d; i < MAX; i++) if (a[i] != r.a[i]) return false; } bool operator < (const BigInt & r) const { if (d != r.d) return d > r.d; for (int i = d; i < MAX; i++) if (a[i] != r.a[i]) return a[i] < r.a[i]; return false; } }; int main(void) { int x; BigInt a; vector v; do { scanf("%d", &x); if (x != -1) { BigInt a(x); v.push_back(a); } } while (x != -1); sort(v.begin(), v.end()); for (int i = 0; i < v.size(); i++) { v[i].print("\n"); } system("pause"); return 0; }