1 solutions
-
0
【算法分析】 模拟题,首先判断边界,然后,判断需要扩展的部分(也就是横线),首先判断当前位置应该是什么,然后是次数,最后拼接即可。
【代码实现】
#include<bits/stdc++.h> using namespace std; int main() { int p1,p2,p3; cin>>p1>>p2>>p3; string s; cin>>s; string res; for(int i=0;i<s.size();i++) { if(i==0||i+1==s.size()||s[i]!='-') { res+=s[i]; } else //说明是- { char x=s[i-1],y=s[i+1]; if(isdigit(x)&&isdigit(y)||isalpha(x)&&isalpha(y)) //同时是数字 { if(x+1==y) //直接后继 { continue;//继续判断下个位置 } else if(x>=y) //不变 { res+=s[i]; } else //x<y { string ans;//当前横线上需要填写的内容 for(char t=x+1;t<y;t++) { for(int j=1;j<=p2;j++) //重复次数 { char x=t; if(p1==1) x=tolower(t); else if(p1==2) x=toupper(t); else x='*'; ans+=x; } } if(p3==2) reverse(ans.begin(),ans.end()); res+=ans; } } else //直接添加 { res+=s[i]; } } } cout<<res; return 0; }
- 1
Information
- ID
- 455
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 10
- Tags
- # Submissions
- 2
- Accepted
- 1
- Uploaded By