Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- int v[10];
- ifstream fin ("numere.in");
- ofstream fout ("numere.out");
- void cifra (int n, int &x){
- while (n!=0){
- if (n%10 > x)
- x = n%10;
- n = n/10;
- }
- }
- int main (){
- int n, x, aux;
- int minim = 10;
- fin >> n;
- for (int i = 1; i <= n; ++i){
- fin >> x;
- int copiex = x;
- while (x){
- aux = 0;
- cifra (x,aux);
- if (x == copiex)
- v[aux]++;
- if (aux != 0 && aux < minim)
- minim = aux;
- x = x/10;
- }
- }
- if (v[0] == n){
- fout << minim;
- for (int i = 1; i < n; ++i)
- fout << 0;
- }
- else {
- bool gasit = 0;
- for (int i = 1; i <= 9 && !gasit; i++)
- if (v[i] != 0){
- fout << i;
- v[i]--;
- gasit = 1;
- }
- for (int i = 0; i <= 9; ++i)
- for (int j = 1; j <= v[i]; ++j)
- fout << i;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement