70分,求解,给关注

P1098 [NOIP2007 提高组] 字符串的展开

```cpp #include <bits/stdc++.h> using namespace std; int p1,p2,p3; char s[105]; void p31(int l,int r) { for(char x=s[l]+1; x<s[r]; x++) for(int j=1; j<=p2; j++) if(p1==3) { cout<<'*'; } else if(p1==1||(x>='0'&&x<='9')) { cout<<char(x); } else if(p1==2){ cout<<char(x-32); } } void p32(int l,int r ) { for(char x=s[l]-1; x>=s[r]+1; x--) for(int j=0; j<p2; j++)if(p1==3) { cout<<'*'; } else if(p1==1||(x>='0'&&x<='9')) { cout<<char(x); } else if(p1==2){ cout<<char(x-32); } } int main() { cin>>p1>>p2>>p3; cin>>s; int len=strlen(s); cout<<s[0]; for(int i=1; i<len; i++) { if(s[i] == '-'&&s[i-1]<s[i+1]&&i!=len-1&&s[i-1]!='-'&&s[i+1]!='-') { if(s[i-1]>='0'&&s[i-1]<='9'&&(s[i+1]>='A'&&s[i+1]<='Z'||s[i+1]>='a'&&s[i+1]<='z')) { cout<<s[i]; } else if(s[i-1]+1!=s[i+1]){ int c=s[i-1]; if(p3 == 1) p31(i-1,i+1); else if(p3 == 2) p32(i+1,i-1); cout<<s[i+1]; i++; } } else { cout<<s[i]; } } return 0; }
by HEROBRINEH @ 2024-05-21 17:53:53


```cpp #include<bits/stdc++.h> using namespace std; int p1,p2,p3; string s; int main(){ cin>>p1>>p2>>p3; cin>>s; int ls=s.size(); for(int i=0;i<ls;i++){ if((s[i]=='-')&&(s[i-1]<s[i+1])&&((isdigit(s[i-1])&&isdigit(s[i+1])) ||(isalpha(s[i-1])&&isalpha(s[i+1])))) { string sx=""; int sa,sb; sa=int(s[i-1]);sb=int(s[i+1]); for(int i=sa+1;i<sb;i++){ for(int j=0;j<p2;j++){ sx+=i; } } if(p1==2&&(isalpha(s[i-1])&&isalpha(s[i+1]))){ for(int i=0;i<sx.size();i++){ sx[i]=toupper(sx[i]); } } if(p3==2) reverse(sx.begin(),sx.end()); if(p1==3){ for(int i=0;i<sx.size();i++) sx[i]='*'; } for(int i=0;i<sx.size();i++) cout<<sx[i]; } else cout<<s[i]; } return 0; }
by lilynan @ 2024-05-28 18:00:42


@[lilynan](/user/1189308) 已关注,前段时间没看到,对不起
by wyh0703 @ 2024-06-12 17:44:57


|