Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- int c[10];
- int main()
- {
- int n;
- ifstream f("numar2.in");
- f>>n;
- int poz=0;
- char buf;
- f>>buf;
- int a=buf-'0',b,cif=0;
- ++c[a];
- for(int i=2;i<=n;++i)
- {
- f>>buf;
- b=buf-'0';
- if(a>=b)
- ++c[b];
- else
- {
- poz=i-1;
- for(int j=0;j<=9;++j)
- c[j]=0;
- ++c[b];
- cif=a;
- }
- a=b;
- }
- f.close();
- ifstream h("numar2.in");
- ofstream g("numar2.out");
- h>>n;
- for(int i=1;i<=poz-1;++i)
- h>>buf,g<<buf;
- for(int j=cif+1;j<=9;++j)
- if(c[j]!=0)
- {
- g<<j,--c[j];
- break;
- }
- ++c[cif];
- for(int j=0;j<=9;++j)
- for(int k=1;k<=c[j];++k)
- g<<j;
- g<<'\n';
- h.close();
- g.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement