Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
3608 | 邓小龙 | 字符串展开 | C++ | Accepted | 0 MS | 260 KB | 2151 | 2024-06-21 21:51:01 |
# include<iostream> # include<algorithm> using namespace std; string s; int p1,p2,p3;//p1大小写*号,p2重复数量,p3正序/逆序 void fun(int p1,int p2,int p3){ int pos=s.find("-"); while(pos!=-1){ string temp_s;// if(s[pos]=='-'){ int num=s[pos+1]-s[pos-1];//间隔字符数量 //如果后字符<=前字符,不操作 if(num<1) {pos=s.find("-",pos+1);continue;} //如果后字符与前字符差1,则只删除"-" if(num==1) {s.erase(pos,1);pos=s.find("-",pos);continue;} if(s[pos-1]>='a'&&s[pos+1]<='z') { if(p1==1){ for(int j=1;j<num;j++) for(int i=1;i<=p2;i++) temp_s=temp_s+(char)(s[pos-1]+j); } else if(p1==2){ for(int j=1;j<num;j++) for(int i=1;i<=p2;i++) temp_s=temp_s+(char)(s[pos-1]+j-32); } else if(p1==3){ for(int j=1;j<num;j++) for(int i=1;i<=p2;i++) temp_s=temp_s+'*'; } if(p3==2) reverse(temp_s.begin(),temp_s.end()); s.replace(pos,1,temp_s); } else if(s[pos-1]>='0'&&s[pos+1]<='9') { if(p1==1||p1==2){ for(int j=1;j<num;j++) for(int i=1;i<=p2;i++) temp_s=temp_s+(char)(s[pos-1]+j); } else if(p1==3){ for(int j=1;j<num;j++) for(int i=1;i<=p2;i++) temp_s=temp_s+'*'; } if(p3==2) reverse(temp_s.begin(),temp_s.end()); s.replace(pos,1,temp_s); } } pos=s.find("-",pos+1); } } int main(){ cin>>p1>>p2>>p3; cin>>s; fun(p1,p2,p3); cout<<s<<endl; return 0; }