90求救

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

肯定是`if(p1==1) cout<<char(j+'a');`挂了,可以参考下我这块: ```cpp if(p3==1) { for(char j=s[i-1]+1;j<s[i+1];j++) for(int p=1;p<=p2;p++) if(p1==1) ans+=change_to_lower(j); else if(p1==2) ans+=change_to_capital(j); else if(p1==3) ans+="*"; } ``` 其中,`change_to_lower`是把大写字母转为小写。 @[panrong](/user/1044970)
by Lizichen_licis @ 2024-03-26 20:24:17


代码块的缩进挂了
by Lizichen_licis @ 2024-03-26 20:25:03


然后最后输出的是`ans`,就相当于你直接输出
by Lizichen_licis @ 2024-03-26 20:26:12


@[Lizichen_licis](/user/749811) ~~听不懂思密达~~
by panrong @ 2024-03-27 19:00:06


我也可以直接给你我的代码
by Lizichen_licis @ 2024-03-27 19:18:35


```cpp #include<cstdio> #include<string> #include<iostream> using namespace std; bool isdigit(char a) { if(a>='0'&&a<='9') return true; else return false; } bool isalpha(char a) { if((a>='A'&&a<='Z')||(a>='a'&&a<='z')) return true; else return false; } char change_to_lower(char a) { if(a>='A'&&a<='Z') a+=32; return a; } char change_to_capital(char a) { if(a>='a'&&a<='z') a-=32; return a; } bool check(char a,char b) { if(isdigit(a)&&isalpha(b)) return false; return true; } bool _check(char a,char b) { if(a=='-'||b=='-') return false; return true; } int main() { int p1,p2,p3; string s,ans=""; scanf("%d%d%d",&p1,&p2,&p3); cin>>s; for(int i=0;i<s.size();i++) { if(s[i]=='-'&&s[i-1]<s[i+1]&&check(s[i-1],s[i+1])&&_check(s[i-1],s[i+1])&&i!=0&&i!=(s.size()-1)) { if(isalpha(s[i-1])&&isalpha(s[i+1])) { if(p3==1) { for(char j=s[i-1]+1;j<s[i+1];j++) for(int p=1;p<=p2;p++) if(p1==1) ans+=change_to_lower(j); else if(p1==2) ans+=change_to_capital(j); else if(p1==3) ans+="*"; } else { for(char j=s[i+1]-1;j>s[i-1];j--) for(int p=1;p<=p2;p++) if(p1==1) ans+=change_to_lower(j); else if(p1==2) ans+=change_to_capital(j); else if(p1==3) ans+="*"; } } else if(isdigit(s[i-1])&&isdigit(s[i+1])) { if(p3==1) for(char j=s[i-1]+1;j<s[i+1];j++) for(int p=1;p<=p2;p++) if(p1==3) ans+="*"; else ans+=j; else for(char j=s[i+1]-1;j>s[i-1];j--) for(int p=1;p<=p2;p++) if(p1==3) ans+="*"; else ans+=j; } continue; } ans+=s[i]; } cout<<ans; return 0; } ```
by Lizichen_licis @ 2024-03-27 19:20:42


不用管那堆子函数,直接看主函数就行 @[panrong](/user/1044970)
by Lizichen_licis @ 2024-03-27 19:21:29


|