Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. int v[10];
  6. ifstream fin ("numere.in");
  7. ofstream fout ("numere.out");
  8.  
  9. void cifra (int n, int &x){
  10.  
  11. while (n!=0){
  12. if (n%10 > x)
  13. x = n%10;
  14. n = n/10;
  15. }
  16. }
  17.  
  18. int main (){
  19.  
  20. int n, x, aux;
  21. int minim = 10;
  22. fin >> n;
  23. for (int i = 1; i <= n; ++i){
  24. fin >> x;
  25. int copiex = x;
  26. while (x){
  27. aux = 0;
  28. cifra (x,aux);
  29. if (x == copiex)
  30. v[aux]++;
  31. if (aux != 0 && aux < minim)
  32. minim = aux;
  33. x = x/10;
  34. }
  35. }
  36.  
  37. if (v[0] == n){
  38. fout << minim;
  39. for (int i = 1; i < n; ++i)
  40. fout << 0;
  41. }
  42. else {
  43. bool gasit = 0;
  44. for (int i = 1; i <= 9 && !gasit; i++)
  45. if (v[i] != 0){
  46. fout << i;
  47. v[i]--;
  48. gasit = 1;
  49. }
  50. for (int i = 0; i <= 9; ++i)
  51. for (int j = 1; j <= v[i]; ++j)
  52. fout << i;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement