#include
#define LIM 1000
//实现形如:a-k-z或-a-k-z或a-k-z-0-9的扩展,并保留-号
void expand(char a[], char b[]);
int judge(char a, char b);
int main()
{
char a[LIM], b[LIM];
scanf("%s", a); //输入a-k-z或-a-k-z或a-k-z-0-9,
expand(a,b);
printf("%s", b);
system("PAUSE");
return (0);
}
int judge(char a, char b)
{
if ('a' <= a <= 'z' && 'a' <= b <= 'z')
return 1;//字母扩展
else if ('0' <= a <= '9' && '0' <= b <= '9')
return 2;//数字扩展
else
return 0;
}
void expand(char s1[],char s2[])
{
int i, j, k;
for (i = j = 0; s1[i] != '\0';++i){
if (s1[i] == '-'){
s2[j] = s1[i];
++j;
} //抄写-,j是-计数器
else if((s1[i+1]=='-') && (judge(s1[i], s1[i+2]) == 1)) { //错误!!中间必须是-才用这个
s2[j] = s1[i];
k = 1;
while(s2[j] < s1[i+2]-1){//应该少一个
s2[++j] = s1[i] + k;
++k;
}
++j;//j必须增1,指向下一个空位,准备下一个字符
}
else if((s1[i+1]=='-') && (judge(s1[i], s1[i+2]) == 2)){//错误!!中间必须是-才用这个
s2[j] = s1[i];
k = 1;
while(s2[j] < s1[i+2]-1){//应该少一个
s2[++j] = s1[i] + k;
++k;
}
++j;//j必须增1,指向下一个空位,准备下一个字符
}
else
s2[j++] = s1[i];
}
//s2[++j] = s1[i+1];多余
//s2[++j] = '\0';错
s2[j]='\0';
}
'a' <= a <= 'z' && 'a' <= b <= 'z' 这种代码是什么意思,没这种写法,应该是
'a' <= a && a<= 'z' && 'a' <= b && b<= 'z'
天,不会c语言,对不起啦
结果是32-1
因为没有符号隔开,所以是连着的!
首先3>0&&1<5成立,故y=4;
此时z=2,x=1;
然后2>0&&2<5也成立,故y=3;
此时z=1,x=2;
接着是1>0&&3<5成立,故y=2;
此时z=0,x=3;
最后0不大于0,故不能再循环,但z--已执行,所以z=-1
结果就是32-1