输入两个非负整数m,n(位数不确定,n>=m)
给定一个字符串构成的文件名,对文件名进行批量改名。(扩展名须保持不变,且扩展名不仅限于MP3,扩充的位数以n的值为参照)
例如:
输入:
99,103
music.MP3
输出
music099.MP3
music100.MP3
music101.MP3
music102.MP3
music103.MP3
#include <stdio.h>
#include <string.h>
void deal(int x,int y,int count,char arr[100])//x是传过去的数字,y是n的位数
{
char tmp[100] = {'\0'};
char X[100] = {'\0'};
strcpy(tmp,arr);
int i = 0;
for(i = 0;i<y;i++)
{
X[i] = x%10+'0';
x = x/10;
}
int j = 0;
for(i = 0;i<y;i++,count--)
{
tmp[count+y-1] = X[i];
}
printf("%s\n",tmp);
}
int main()
{
int m = 0;
int n = 0;
char arr[100] = {'\0'};
scanf("%d,%d",&m,&n);
getchar();
gets(arr);
int tmp = 1;
int a = 1;
int b = 1;
while(m%tmp>=10)
{
a++;
tmp = tmp*10;
}//m的位数
tmp = 1;
while(n/tmp>=10)
{
b++;
tmp = tmp*10;
}//n的位数
int count = 0;
for(count = 0;arr[count]!='.';count++);//arr[count]为'.'
int length = strlen(arr);
int i = 0;
for(i = length-1;i>=count;i--)
{
arr[i+b] = arr[i];
}//将'.'后的字符向后移动n的位数,为前面的数字腾出来位置
//printf("%d\n",b);
//printf("%s\n",arr);
int k = m;
for(k = m;k<=n;k++)
{
deal(k,b,count,arr);
}
return 0;
}