先嘲讽,再看题,好习惯
by jkary @ 2023-08-22 11:26:25
注意到程序里有一行:
```
if(s[i]!='-') cout<<s[i];
```
在循环时读到减号上一个字符就会先输出
但是后面有一行
```
for(char j=s[i1];j<=s[i+1];i++)
.......
(other code)
cout<<j;
```
这里会把减号左边的字符重新输出一次,重复了
by shutan_hyc81010 @ 2023-08-23 09:06:56
@[shutan_hyc81010](/user/1000496)
我的代码是这样写的
```cpp
//核心代码
for(int i=0;i<len;i++)
{
if(s[i]=='-')
{
if(i==0||!aspace(s[i-1],s[i+1])||s[i-1]>s[i+1])
{
cout<<'-'<<s[i+1];
i++;
continue;
}
if(c==1)
{
for(int j=(int)s[i-1]+1;j<(int)s[i+1];j++)
{
for(int k=1;k<=b;k++)
{
if(a==1)
printf("%c",tolower((char)j));
if(a==2)
printf("%c",toupper((char)j));
if(a==3)
cout<<'*';
}
}
}
if(c==2)
{
for(int j=(int)s[i+1]-1;j>(int)s[i-1];j--)
{
for(int k=1;k<=b;k++)
{
if(a==1)
printf("%c",tolower((char)j));
if(a==2)
printf("%c",toupper((char)j));
if(a==3)
cout<<'*';
}
}
}
}
else
cout<<s[i];
}
```
aspace函数code:
```
int aspace(char c1,char c2)
{
if(c1>=48 and c1<=57 and c2>=48 and c2<=57 and c1!=c2) return 1;
else if(c1>=97 and c1<=122 and c2>=97 and c2<=122 and c1!=c2) return 2;
else return false;
}
by shutan_hyc81010 @ 2023-08-23 09:08:51
@[shutan_hyc81010](/user/1000496) 有点没看懂
by daoling @ 2023-09-02 22:15:46
@[daoling](/user/919172) aspace 函数代表的是能否展开及应填充什么字符(48-57是数字,97-122字母)
by shutan_hyc81010 @ 2023-09-05 14:10:50
@[daoling](/user/919172) 循环,找到减号后特判是否有不合法的展开,如果合法则按照要求循环输出
by shutan_hyc81010 @ 2023-09-05 14:12:35
@[shutan_hyc81010](/user/1000496) OKOKOK
by daoling @ 2023-09-05 19:40:39