Advertisement
a53

numar2

a53
Feb 28th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. int c[10];
  4.  
  5. int main()
  6. {
  7. int n;
  8. ifstream f("numar2.in");
  9. f>>n;
  10. int poz=0;
  11. char buf;
  12. f>>buf;
  13. int a=buf-'0',b,cif=0;
  14. ++c[a];
  15. for(int i=2;i<=n;++i)
  16. {
  17. f>>buf;
  18. b=buf-'0';
  19. if(a>=b)
  20. ++c[b];
  21. else
  22. {
  23.  
  24. poz=i-1;
  25. for(int j=0;j<=9;++j)
  26. c[j]=0;
  27. ++c[b];
  28. cif=a;
  29. }
  30. a=b;
  31. }
  32. f.close();
  33. ifstream h("numar2.in");
  34. ofstream g("numar2.out");
  35. h>>n;
  36. for(int i=1;i<=poz-1;++i)
  37. h>>buf,g<<buf;
  38. for(int j=cif+1;j<=9;++j)
  39. if(c[j]!=0)
  40. {
  41. g<<j,--c[j];
  42. break;
  43. }
  44. ++c[cif];
  45. for(int j=0;j<=9;++j)
  46. for(int k=1;k<=c[j];++k)
  47. g<<j;
  48. g<<'\n';
  49. h.close();
  50. g.close();
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement