(c语言)
(参考函数原型:void del(char* str))
输入输出格式要求:
只编写函数,请勿输出其他字符
例如:
str为:aa*++1123.,
调用del函数之后str为:aa*+1123.,
实在不会了QAQ谢谢大佬拯救
按照题目要求编写的缩减相同字符的C语言程序如下
#include<stdio.h>
#include<string.h>
void del(char* str){
int len,i,j;
len=strlen(str);
for(i=1;i<len;i++){
if('a'<=*(str+i) && *(str+i)<='z' || 'A'<=*(str+i) && *(str+i)<='Z' || '0'<=*(str+i) && *(str+i)<='9'){
}else{
if(*(str+i-1)==*(str+i)){
for(j=i;j<len;j++){
*(str+j)=*(str+j+1);
}
i--;
len=len-1;
}
}
}
}
int main(){
char s[100];
fgets(s,100,stdin);
del(s);
printf("%s",s);
return 0;
}
追问QAQ大佬这个len--是为啥啊
追答因为比如有字符串"abc++de",执行for_j循环后"de"向前移覆盖后面的加号,变成了"abc+de"字符串总长度短了一,所以下次for循环前要总长度减一.
追问啊好的,
谢谢大佬
爱了