Advertisement
Gamerul_08

Untitled

Jun 26th, 2020
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. struct numere
  5. {
  6. int x,nr;
  7. }q[10];
  8. int comparare (numere a, numere b)
  9. {
  10. if((a.nr>b.nr)||(a.nr==b.nr&&a.x>b.x)) return 1;
  11. else return 0;
  12. }
  13. int i,n,x,u,v[10],a,mn,nr,p=0,j,b[11],c[102];
  14. int main()
  15. {
  16. cin>>n;
  17. for(i=1;i<=n;i++)
  18. {
  19. cin>>x;
  20. a=x;
  21. for(j=0;j<=9;j++)
  22. {
  23. b[j]=0;
  24. }
  25. while(a!=0)
  26. {
  27. u=a%10;
  28. v[u]++;
  29. b[u]=1;
  30. a=a/10;
  31. }
  32. nr=0;
  33. for(j=0;j<=9;j++)
  34. {
  35. if(b[j]==1) nr++;
  36. }
  37. if(nr==2) {p++;c[p]=x;}
  38. }
  39. mn=999999999;
  40. for(i=0;i<=9;i++)
  41. {
  42. if(v[i]<mn) {mn=v[i];x=i;}
  43. }
  44. cout<<x<<"\n";
  45. for(i=0;i<=9;i++)
  46. {
  47. q[i].x=i;
  48. q[i].nr=v[i];
  49. }
  50. sort(q,q+10,comparare);
  51. for(i=0;i<=9;i++) cout<<q[i].x<<" ";
  52. cout<<"\n";
  53. sort(c,c+p+1);
  54. if(p==0) cout<<-1;
  55. else for(i=1;i<=p;i++)
  56. {
  57. cout<<c[i]<<" ";
  58. }
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement