本帖最后由 jhq999 于 2022-3-19 22:15 编辑 int outmin(int innum)
{
innum++;
int len=0,num=innum,i=0;
while (num)len++,num/=10;
int *fj=new int[len];
num=innum;
for (i=0;i<len;i++)
{
fj[len-1-i]=num%10;
num/=10;
}
a=len/2+len%2;
for (i = 0; i < len/2; i++)
{
if(fj[len/2-i-1]<fj[a+i])
{
fj[a-1]++;
break;
}
}
for (i = 0; i < len/2; i++)fj[len-i-1]=fj[i];
for (i = 0,num=0; i < len; i++)num=num*10+fj[i];
delete[] fj;
return num;
}
int main()
{
int n=0,*innum=NULL,i=0;
scanf("%d",&n);
innum=new int[n];
for (i = 0; i < n; i++)
{
scanf("%d",innum+i);
innum[i]=outmin(innum[i]);
}
for (i = 0; i < n; i++)
{
printf("%d\n",innum[i]);
}
delete[] innum;
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int outmin(int innum)
{
innum++;
int len=0,num=innum,a=0,b=0,c=0,i=0;
while (num)len++,num/=10;
num=innum;
b=1;
for (i=0;i<len/2;i++)
{
num/=10;
b*=10;
}
c=b;
b=innum-num*b;
innum=len%2?num/10:num;
a=0;
for (i=0;i<len/2;i++)
{
a=a*10+innum%10;
innum/=10;
}
if (b>a)
{
num++;
}
num=num*c+a;
return num;
}
int main()
{
int n=0,*innum=NULL,i=0;
scanf("%d",&n);
innum=new int[n];
for (i = 0; i < n; i++)
{
scanf("%d",innum+i);
innum[i]=outmin(innum[i]);
}
for (i = 0; i < n; i++)
{
printf("%d\n",innum[i]);
}
delete[] innum;
return 0;
}
|