Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- #include<bits/stdc++.h>
- ifstream fin("unific.in");
- ofstream fout("unific.out");
- int n;
- long long v[100001];
- int frcifre[10];
- int maximAppCifra;
- int cifMax;
- int i, k;
- long long nr, x;
- void adaugaLaFrCifre(long long x) {
- if (x == 0) {
- frcifre[0]++;
- }
- while (x) {
- frcifre[x%10]++;
- x /= 10;
- }
- }
- bool comun(long long a, long long b) {
- bool fra[10];
- for (int c = 0; c<=9; c++) {
- fra[c] = 0;
- }
- if (a == 0) {
- fra[0] = 1;
- } else {
- while (a) {
- fra[a%10] = 1;
- a /= 10;
- }
- }
- if (b == 0 && fra[0] == 1) {
- return 1;
- }
- while (b) {
- if (fra[b%10] == 1) {
- return 1;
- }
- b /= 10;
- }
- return 0;
- }
- long long unifica(long long y, long long x) {
- short uz[10];
- long long p = 0;
- int UltimaCifraAdaugataY = 0;
- int nrcifreY = 0;
- for (int c = 0; c<=9; c++) {
- uz[c] = 0;
- }
- long long z = y;
- if (z == 0) {
- uz[0] = 1;
- } else {
- while (z > 0) {
- uz[z%10] = 1;
- z /= 10;
- }
- }
- z = x;
- if (z == 0 && uz[0]) {
- uz[0] = 2;
- } else {
- p = 1;
- x = 0;
- while (z > 0) {
- short c = z%10;
- if (uz[c] == 0) {
- x = x + c*p;
- p *= 10;
- } else {
- uz[c] = 2;
- }
- z /= 10;
- }
- }
- if (y>0) {
- z = y;
- y = 0;
- p = 1;
- while (z) {
- short c = z%10;
- if (uz[c] == 1) {
- y = y + p*c;
- p *= 10;
- nrcifreY++;
- UltimaCifraAdaugataY = c;
- }
- z /= 10;
- }
- }
- if (x*y > 0) {
- if (UltimaCifraAdaugataY == 0) {
- while (p / 10 > y) {
- p /= 10;
- }
- }
- return x*p+y;
- } else {
- if (x > 0) {
- if (nrcifreY > 0) {
- x *= 10;
- }
- return x;
- } else {
- if (nrcifreY == 0) {
- y = -1;
- }
- return y;
- }
- }
- }
- int main() {
- fin >> n;
- fin >> v[1];
- adaugaLaFrCifre(v[1]);
- i = 1;
- k = 1;
- while (i<n) {
- fin >> v[++k];
- adaugaLaFrCifre(v[k]);
- i++;
- while (comun(v[k-1], v[k]) && k > 1) {
- long long x = unifica(v[k], v[k-1]);
- if (x == -1) {
- k -= 2;
- } else {
- v[k-1] = x;
- k--;
- }
- }
- }
- for (int j = 0; j<=9; j++) {
- if (frcifre[j] > maximAppCifra) {
- maximAppCifra = frcifre[j];
- cifMax = j;
- }
- }
- fout << cifMax << endl << k << endl;
- for (int j = 1; j<=k; j++) {
- fout << v[j] << " ";
- }
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement