Pagini recente » Cod sursa (job #1449839) | Cod sursa (job #2787036) | Cod sursa (job #1496216) | Cod sursa (job #806473) | Cod sursa (job #1259561)
#include <fstream>
#include <cmath>
using namespace std;
ifstream f("alibaba.in");
ofstream g("alibaba.out");
int n,k,x,p,nr,c1,c2,c3;
int main()
{
f>>n>>k;
f>>x;
p = pow(10,n)/10;
nr = 0;
while(nr < k && p > 0)
{
c1 = x/p%10;
p = p/10;
if(p == 1) break;
c2 = x/p%10;
if(c1 > c2)
{
x = x/(p*10)*p + x%p;
nr++;
}
if(c1 < c2)
{
x = x/(p*100)*p*10 + x%(p*10);
nr++;
}
if(c1 == c2)
{
p = p/10;
c3 = x/p%10;
if(c2 >= c3)
{
x = x/(p*10)*p + x%p;
nr++;
}
if(c2 < c3)
{
x = x/(p*100)*p*10 + x%(p*10);
nr++;
}
p = p*10;
}
}
if(nr < k)
{
p = pow(10,k-nr);
if(x%p > x/p) x = x%p;
else x = x/p;
}
g<<x;
return 0;
}