SHARE
TWEET

Untitled

a guest Dec 14th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// solutie - Moca Andrei
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. class InParser {
  5. private:
  6.     FILE *fin;
  7.     char *buff;
  8.     int sp;
  9.     char read_ch() {
  10.         ++sp;
  11.         if (sp == 4096) {
  12.             sp = 0;
  13.             fread(buff, 1, 4096, fin);
  14.         }
  15.         return buff[sp];
  16.     }
  17. public:
  18.     InParser(const char* nume) {
  19.         fin = fopen(nume, "r");
  20.         buff = new char[4096]();
  21.         sp = 4095;
  22.     }
  23.     InParser& operator >> (int &n) {
  24.         char c;
  25.         while (!isdigit(c = read_ch()) && c != '-');
  26.         int sgn = 1;
  27.         if (c == '-') {
  28.             n = 0;
  29.             sgn = -1;
  30.         } else {
  31.             n = c - '0';
  32.         }
  33.         while (isdigit(c = read_ch())) {
  34.             n = 10 * n + c - '0';
  35.         }
  36.         n *= sgn;
  37.         return *this;
  38.     }
  39. };
  40. class OutParser {
  41. private:
  42.     FILE *fout;
  43.     char *buff;
  44.     int sp;
  45.     void write_ch(char ch) {
  46.         if (sp == 50000) {
  47.             fwrite(buff, 1, 50000, fout);
  48.             sp = 0;
  49.             buff[sp++] = ch;
  50.         } else {
  51.             buff[sp++] = ch;
  52.         }
  53.     }
  54. public:
  55.     OutParser(const char* name) {
  56.         fout = fopen(name, "w");
  57.         buff = new char[50000]();
  58.         sp = 0;
  59.     }
  60.     ~OutParser() {
  61.         fwrite(buff, 1, sp, fout);
  62.         fclose(fout);
  63.     }
  64.     OutParser& operator << (int vu32) {
  65.         if (vu32 <= 9) {
  66.             write_ch(vu32 + '0');
  67.         } else {
  68.             (*this) << (vu32 / 10);
  69.             write_ch(vu32 % 10 + '0');
  70.         }
  71.         return *this;
  72.     }
  73.     OutParser& operator << (char ch) {
  74.         write_ch(ch);
  75.         return *this;
  76.     }
  77.     OutParser& operator << (const char *ch) {
  78.         while (*ch) {
  79.             write_ch(*ch);
  80.             ++ch;
  81.         }
  82.         return *this;
  83.     }
  84. };
  85. InParser fin("sort4.in");
  86. OutParser fout("sort4.out");
  87. struct elem {
  88.     int nr, sum, prod, val;
  89.     bool operator < (const elem& e) const
  90.     {
  91.         if (nr != e.nr) return nr > e.nr;
  92.         if (sum != e.sum) return sum < e.sum;
  93.         if (prod != e.prod) return prod < e.prod;
  94.         return val < e.val;
  95.     }
  96. };
  97. int nrcif, scif, pcif, freq, aux;
  98. inline void prelucrare(int x)
  99. {
  100.     freq = scif = 0;
  101.     pcif = 1;
  102.     while (x)
  103.     {
  104.         freq |= (1 << (x % 10));
  105.         scif += (x % 10);
  106.         pcif *= (x % 10);
  107.         x /= 10;
  108.     }
  109.     nrcif = __builtin_popcount(freq);
  110. }
  111. vector<elem> v;
  112. int n, x;
  113. int main()
  114. {
  115.     fin >> n;
  116.     v = vector<elem>(n);
  117.     for (int i = 0; i < n; ++i)
  118.     {
  119.         fin >> x;
  120.         prelucrare(x);
  121.         v[i] = {nrcif, scif, pcif, x};
  122.     }
  123.     sort(v.begin(), v.end());
  124.     for (const elem& e : v)
  125.         fout << e.val << ' ';
  126.     return 0;
  127. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top