90分求助!!!

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

@[inkling_127](/user/1060971) ```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-08-24 13:38:32


求关
by HEROBRINEH @ 2024-08-24 13:38:53


```cpp #include<bits/stdc++.h> using namespace std; int p1,p2,p3,i=0,k; char ch[300],be,af,f,j,p; int main() { scanf("%d%d%d%s",&p1,&p2,&p3,ch); while(ch[i]){ be=ch[i-1];af=ch[i+1];f=ch[i]; if(f=='-'&&af>be&&(be>='0'&&af<='9'||be>='a'&&af<='z')){ for(p3==1?j=be+1:j=af-1; p3==1?j<af:j>be; p3==1?j++:j--){ p=j if(p1==2); p=(p>='a')?p-32:p else if(p1==3) p='*'; for(k=0; k<p2; k++) printf("%c",p); } } else printf("%c",f); i++; } return 0; }
by dp28 @ 2024-08-24 13:39:21


@[dp28](/user/1223232) 加油
by dp28 @ 2024-08-24 13:39:42


|