刚才准备去上课,一看时间,马上就打铃了,那就再t a o一节吧。。

昨天的一日一题:

题目不是很难,不过要考虑的全面,不然会一直wa,对0和9进行处理。

贴代码:

#include<stdio.h>
# include
<string.h>
# include
<stdlib.h>
int cmp(const void *a, const void *b)
{
return *(char *) a - *(char *)b;
}
int main()
{
int i,len,n,count1,count2,index;
char str[1005];
scanf(
"%d",&n);
getchar();
while(n--)
{
gets(str);
len
=strlen(str);
count1
=1;
count2
=1;
for(i=len-1;i>=0;i--)
{
if(str[i]!='0' && count1==1) {str[i]=str[i]-1;count1=0;}
else if(count1==0 && str[i]!='9') {str[i]=str[i]+1;count2=0;}
if(count1==0 && count2==0 ) break;
}
index
=i+1;
if(count2==1)
{
printf(
"1");
}
qsort(str
+index,len-index,sizeof(str[index]),cmp);
puts(str);
}
return 0;
}
posted on 2011-03-24 10:38  奋斗青春  阅读(217)  评论(0编辑  收藏  举报