样例二过不去,悬赏两关(非常完美解决悬赏三关)

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

看一下我的代码吧,90分,你看看有什么可以借鉴的 ```cpp #include<bits/stdc++.h> using namespace std; void f1(int n,int m,int p,string s) { while(s.find('-')!=-1) { string str1=""; int t=s.find('-'); for(int i=1; i<=s[t+1]-s[t-1]-1; i++) { for(int j=1; j<=m; j++) { if(n==3) str1+='*'; else if(n==1){ str1+=tolower(char(s[t-1]+i)); } else { str1+=toupper(char(s[t-1]+i)); } } } if(p==2) reverse(str1.begin(),str1.end()); if(abs(s[t-1]-s[t+1])>25||s[t+1]<=s[t-1])s.replace(t,1,","); else s.replace(t,1,str1); } while(s.find(',')!=-1) { s.replace(s.find(','),1,"-"); } cout<<s; } int main() { int p1,p2,p3; string str; cin>>p1>>p2>>p3>>str; f1(p1,p2,p3,str); return 0; } ```
by Cy_AlphaKai_CCF @ 2023-10-21 19:39:30


|