Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream in("pluton.in");
- ofstream out("pluton.out");
- int n, mat[4005][13], x, vec[83][4005], v[4005], k = 0, b[4005], b2[4005];
- int nrPlutoane, PlutonMare, Plutoane, p, pmax;
- void cifre(int pos, int val, int cop) {
- int s = 0;
- while(val) {
- mat[pos][val % 10] ++;
- s += val % 10;
- val /= 10;
- }
- if(vec[s][0] == 0)
- v[++k] = s;
- vec[s][++vec[s][0]] = pos;
- }
- bool egal(int pos1, int pos2) {
- for(int i = 0; i <= 9; ++i)
- if(mat[pos1][i] != mat[pos2][i])
- return 0;
- return 1;
- }
- int main() {
- in >> n;
- for(int i = 1; i <= n; ++i) {
- in >> x;
- mat[i][10] = x;
- cifre(i, x, x);
- }
- for(int i = 1; i <= k; ++i) {
- p = 0;
- for(int j = 1; j <= vec[v[i]][0]; ++j) {
- int pozitie1 = vec[v[i]][j];
- if(mat[pozitie1][11] == 0){
- nrPlutoane ++;
- int nr = 1;
- p = 0;
- mat[pozitie1][11] = 1;
- b[++p] = mat[pozitie1][10];
- for(int t = j + 1; t <= vec[v[i]][0]; ++t) {
- int pozitie2 = vec[v[i]][t];
- if(mat[pozitie2][11] == 0)
- if(egal(pozitie1, pozitie2)) {
- mat[pozitie2][11] = 1;
- ++nr;
- b[++p] = mat[pozitie2][10];
- }
- }
- if(nr > PlutonMare) {
- PlutonMare = nr;
- Plutoane = 1;
- for(int i = 1; i <= p; ++i)
- b2[i] = b[i];
- pmax = p;
- }
- else if(nr == PlutonMare) {
- Plutoane ++;
- }
- }
- }
- }
- out << nrPlutoane << '\n' << PlutonMare << '\n' << Plutoane << '\n';
- for(int i = 1; i <= pmax; ++i)
- out << b2[i] << ' ';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement