这个代码有啥错

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

如果字符不是连字符,它是需要被输出的 ```cpp #include<bits/stdc++.h> using namespace std; typedef long long ll; int p1,p2,p3; string s; bool p(char a,char b){ if(isdigit(a) && isdigit(b)) return 1; if(isalpha(a) && isalpha(b)) return 1; return 0; } void f(char a,char b){ if(p3==1){ for(char i=a+1;i<b;++i){ for(int j=0;j<p2;++j){ if(p1==1) printf("%c",tolower(i)); else if(p1==2) printf("%c",toupper(i)); else cout<<"*"; } } } else{ for(char i=b-1;i>a;--i){ for(int j=0;j<p2;++j){ if(p1==1) cout<<char(tolower(i)); else if(p1==2) cout<<char(toupper(i)); else cout<<"*"; } } } } int main(){ cin>>p1>>p2>>p3>>s; for(int i=0;i<s.size();++i){ if(s[i]=='-'){ if(s[i+1]-s[i-1]==1) continue; else if(s[i+1]<=s[i-1]){ cout<<s[i]; continue; } else if(p(s[i-1],s[i+1])){ f(s[i-1],s[i+1]); continue; } else cout<<s[i];//看这里!! } } return 0; } ```
by LH4432 @ 2024-07-04 13:56:31


@[LH4432](/user/936640) 不好意思打错了…… ```cpp #include<bits/stdc++.h> using namespace std; typedef long long ll; int p1,p2,p3; string s; bool p(char a,char b){ if(isdigit(a) && isdigit(b)) return 1; if(isalpha(a) && isalpha(b)) return 1; return 0; } void f(char a,char b){ if(p3==1){ for(char i=a+1;i<b;++i){ for(int j=0;j<p2;++j){ if(p1==1) printf("%c",tolower(i)); else if(p1==2) printf("%c",toupper(i)); else cout<<"*"; } } } else{ for(char i=b-1;i>a;--i){ for(int j=0;j<p2;++j){ if(p1==1) cout<<char(tolower(i)); else if(p1==2) cout<<char(toupper(i)); else cout<<"*"; } } } } int main(){ cin>>p1>>p2>>p3>>s; for(int i=0;i<s.size();++i){ if(s[i]=='-'){ if(s[i+1]-s[i-1]==1) continue; else if(s[i+1]<=s[i-1]){ cout<<s[i]; continue; } else if(p(s[i-1],s[i+1])){ f(s[i-1],s[i+1]); continue; } cout<<s[i]; }else{ cout<<s[i];//看这里!! } } return 0; } ```
by LH4432 @ 2024-07-04 13:58:23


@[LH4432](/user/936640) 谢谢,已互关
by zby2_ @ 2024-07-15 16:37:13


|