Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. ifstream in("pluton.in");
  6. ofstream out("pluton.out");
  7.  
  8. int n, mat[4005][13], x, vec[83][4005], v[4005], k = 0, b[4005], b2[4005];
  9. int nrPlutoane, PlutonMare, Plutoane, p, pmax;
  10. void cifre(int pos, int val, int cop) {
  11.     int s = 0;
  12.     while(val) {
  13.         mat[pos][val % 10] ++;
  14.         s += val % 10;
  15.         val /= 10;
  16.     }
  17.     if(vec[s][0] == 0)
  18.         v[++k] = s;
  19.     vec[s][++vec[s][0]] = pos;
  20. }
  21.  
  22. bool egal(int pos1, int pos2) {
  23.     for(int i = 0; i <= 9; ++i)
  24.         if(mat[pos1][i] != mat[pos2][i])
  25.             return 0;
  26.     return 1;
  27. }
  28.  
  29. int main() {
  30.  
  31.     in >> n;
  32.     for(int i = 1; i <= n; ++i) {
  33.         in >> x;
  34.         mat[i][10] = x;
  35.         cifre(i, x, x);
  36.     }
  37.     for(int i = 1; i <= k; ++i) {
  38.         p = 0;
  39.         for(int j = 1; j <= vec[v[i]][0]; ++j) {
  40.             int pozitie1 = vec[v[i]][j];
  41.             if(mat[pozitie1][11] == 0){
  42.                 nrPlutoane ++;
  43.                 int nr = 1;
  44.                 p = 0;
  45.                 mat[pozitie1][11] = 1;
  46.                 b[++p] = mat[pozitie1][10];
  47.                 for(int t = j + 1; t <= vec[v[i]][0]; ++t) {
  48.                     int pozitie2 = vec[v[i]][t];
  49.                     if(mat[pozitie2][11] == 0)
  50.                         if(egal(pozitie1, pozitie2)) {
  51.                             mat[pozitie2][11] = 1;
  52.                             ++nr;
  53.                             b[++p] = mat[pozitie2][10];
  54.                         }
  55.                 }
  56.                 if(nr > PlutonMare) {
  57.                     PlutonMare = nr;
  58.                     Plutoane = 1;
  59.                     for(int i = 1; i <= p; ++i)
  60.                         b2[i] = b[i];
  61.                     pmax = p;
  62.                 }
  63.                 else if(nr == PlutonMare) {
  64.                     Plutoane ++;
  65.                 }
  66.             }
  67.         }
  68.     }
  69.     out << nrPlutoane << '\n' << PlutonMare << '\n' << Plutoane << '\n';
  70.     for(int i = 1; i <= pmax; ++i)
  71.         out << b2[i] << ' ';
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement