本关任务:规定输入的字符串中只包含字母和*号。给定程序的功能是将字符串中的前导*号全部移到字符串的尾部。
测试输入:
***abcd
预期输出:
abcd***
源代码:
#include <stdio.h>
void fun( char *a )
{
int i=0,n=0;
char *p;
p=a;
while (*p=='*') {
n++;
p++;
}
while(*p){
a[i]=*p;
i++;
p++;
}
while(n!=0){
a[i]='*';
i++;
n--;
}
a[i]='\0';
}
int main(){
char s[81];
int n=0;
scanf("%s",s);
fun( s );
printf("The string after oveing: \n");
puts(s);
return 0;
}
运行结果:
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有