开头打-考虑了 连续的-考虑了 本地几个自己搞得输入都没什么问题 交上来全WA了
#include <stdio.h>
#include <stdbool.h>
#include <ctype.h>
#include <math.h>
#include <assert.h>
char ch;
char prev='-';
bool alert=false;//有没有“-”
int stus=0;/*状态*/
int rpt=0;/*重复次数*/
int rev=0;/*是否逆转*/
void alertResponse();
int main(){
char BufferSheild;
scanf("%d %d %d",&stus,&rpt,&rev);
BufferSheild=getchar();
while((ch=(getchar()))!='\n'){
if(!alert&&ch!='-'){ //不在警戒状态
printf("%c",ch);
prev=ch;
}
else if(!alert&&ch=='-'){//警戒开启,prev为-前的字符
alert=true;
}
else if(alert&&ch!='-'){//警戒状态后,ch现在是-后面的字符,但也有可能是假的
//这时候看看 - 前面一个字符是什么
if(prev!='-'){//真
alertResponse();
}
else if(prev=='-'){//丁真
alert=false;
printf("-");
}
}
else if(alert&&ch=='-'){// 假的
alert=false;
printf("--");
prev=ch;
}
}
return 0;
}
void alertResponse(){// prev - ch
char tmp;// 移动字符
if(isdigit(prev)&&isdigit(ch)&&prev<ch){//数字展开
if(rev==1){// 正
for(tmp=prev+1;tmp<ch;++tmp){
for(int i=0;i<rpt;++i){( (stus==3)?printf("*"):printf("%c",tmp) );}
}
}
else if(rev==2){//反
for(tmp=ch-1;tmp>prev;--tmp){
for(int i=0;i<rpt;++i){( (stus==3)?printf("*"):printf("%c",tmp) );}
}
}
}
else if(isalpha(prev)&&isalpha(ch)&&prev<ch){//字母展开
if(rev==1){// 正
for(tmp=prev+1;tmp<ch;++tmp){
for(int i=0;i<rpt;++i){
switch(stus){
case 1:printf("%c",tolower(tmp));break;
case 2:printf("%c",toupper(tmp));break;
case 3:printf("*");break;
}
}
}
}
else if(rev==2){//反
for(tmp=ch-1;tmp>prev;--tmp){
for(int i=0;i<rpt;++i){
switch(stus){
case 1:printf("%c",tolower(tmp));break;
case 2:printf("%c",toupper(tmp));break;
case 3:printf("*");break;
}
}
}
}
}
else{
printf("-");
}
printf("%c",ch);
alert=false;
prev=ch;
return ;
}
各路大佬有空帮看看吧 孩子OI才入门