数据过水

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

附议 还有如下代码 ```cpp #include<bits/stdc++.h> using namespace std; inline int read(){ int s=0; int w=1; char ch=getchar(); for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') w=-1; for(;ch>='0'&&ch<='9';ch=getchar()) s=s*10+ch-'0'; return s*w; } int p1,p2,p3; string a; string ans; int main(){ p1=read(); p2=read(); p3=read(); cin>>a; for(int i=0;i<a.size();i++){ if(a[i]=='-'&&(abs(a[i-1]-a[i+1])<26||abs(a[i-1]-a[i+1])<9)&&a[i-1]!='-'&&a[i+1]!='-'){ if(a[i+1]-1==a[i-1]) continue; if(a[i+1]<=a[i-1]){ ans+=a[i]; continue; } if(p1==3) if(p3==1) for(int j=a[i-1]+1;j<a[i+1];j++) for(int k=1;k<=p2;k++) ans+='*'; else for(int j=a[i+1]-1;j>=a[i-1]+1;j--) for(int k=1;k<=p2;k++) ans+='*'; if(p1==2) if(p3==1) // if(a[i-1]>='0'&&a[i-1]<='9'&&a[i+1]>='0'&&a[i+1]<='9') // // for(int j=a[i-1]+1;j<a[i+1];j++) // // for(int k=1;k<=p2;k++) // // ans+=(char)j; // // else // // for(int j=a[i-1]+1;j<a[i+1];j++) // // for(int k=1;k<=p2;k++) // // ans+=(char)j-'a'+'A'; for(int j=a[i-1]+1;j<a[i+1];j++) for(int k=1;k<=p2;k++) ans+=(char)j-'a'+'A'; else if(a[i-1]>='0'&&a[i-1]<='9'&&a[i+1]>='0'&&a[i+1]<='9') for(int j=a[i-1]+1;j<a[i+1];j++) for(int k=1;k<=p2;k++) ans+=(char)j; else for(int j=a[i+1]-1;j>=a[i-1]+1;j--) for(int k=1;k<=p2;k++) ans+=(char)j-'a'+'A'; if(p1==1) if(p3==1) for(int j=a[i-1]+1;j<a[i+1];j++) for(int k=1;k<=p2;k++) ans+=(char)j; else for(int j=a[i+1]-1;j>=a[i-1]+1;j--) for(int k=1;k<=p2;k++) ans+=(char)j; } else ans+=a[i]; } cout<<ans; return 0; } ``` 注释部分才是正解,但是注释下面的代码却也能AC
by Tachibana27 @ 2023-09-20 15:26:09


@[chen_zhe](/user/8457) @[小粉兔](/user/10703)
by Tachibana27 @ 2023-09-20 15:52:38


+1
by zjinze @ 2023-09-20 15:56:29


+1
by kevin1616 @ 2023-09-20 16:03:55


你们得给具体的 hack 数据并说明 hack 的原理
by 小粉兔 @ 2023-09-20 16:47:09


@[小粉兔](/user/10703) 代码 ```cpp #include<bits/stdc++.h> using namespace std; string s; bool isnumber(char st,char ed){ return (st >= '0' && st <= '9') && (ed >= '0' && ed <= '9'); } signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int p1,p2,p3; cin >> p1 >> p2 >> p3 >> s; for(register int i = 0;i < s.size();++i){ cout << s[i]; if(i == s.size() - 1)break; if(s[i + 1] == '-' && s[i] < s[i + 2] && !isnumber(s[i],s[i + 2]) && s[i + 2] != '-' && s[i] != '-' && s[i] >= 'a' && s[i] <= 'z' && s[i + 2] >= 'a' && s[i + 2] <= 'z'){ if(p3 == 1) { if(p1 == 1) { for(register int j = 1;j < s[i + 2] - s[i];++j) { for(register int k = 1;k <= p2;++k) { cout << char(s[i] + j); } } } else if(p1 == 2) { for(register int j = 1;j < s[i + 2] - s[i];++j){ for(register int k = 1;k <= p2;++k){ cout << char(s[i] - 'a' + 'A' + j); } } } else { for(register int j = 1;j < s[i + 2] - s[i];++j){ for(register int k = 1;k <= p2;++k){ cout << '*'; } } } } else { if(p1 == 1) { for(register int j = s[i + 2] - s[i] - 1;j >= 1;--j) { for(register int k = 1;k <= p2;++k) { cout << char(s[i] + j); } } } else if(p1 == 2) { for(register int j = s[i + 2] - s[i] - 1;j >= 1;--j) { for(register int k = 1;k <= p2;++k) { cout << char(s[i] -'a' + 'A' + j); } } } else { for(register int j = 1;j < s[i + 2] - s[i];--j) { for(register int k = 1;k <= p2;++k) { cout << '*'; } } } } i++; } if(s[i + 1] == '-' && s[i] < s[i + 2] && isnumber(s[i],s[i + 2]) && s[i + 2] != '-' && s[i] != '-' && s[i] >= '0' && s[i] <= '9' && s[i + 2] >= '0' && s[i + 2] <= '9'){ if(p3 == 1) { if(p1 != 3) { for(register int j = 1;j < s[i + 2] - s[i];++j) { for(register int k = 1;k <= p2;++k) { cout << char(s[i] + j); } } } else { for(register int j = 1;j < s[i + 2] - s[i];--j)//here { for(register int k = 1;k <= p2;++k) { cout << '*'; } } } } else { if(p1 != 3) { for(register int j = s[i + 2] - s[i] - 1;j >= 1;--j) { for(register int k = 1;k <= p2;++k) { cout << char(s[i] + j); } } } else { for(register int j = 1;j < s[i + 2] - s[i];++j) { for(register int k = 1;k <= p2;++k) { cout << '*'; } } } } i++; } } return 0; } ``` hack ``` 3 2 2 a-d ``` output ``` a****d ``` 使用以上代码会无限循环,数据过水原因就是没有$p1 = 3$ 的情况
by gghack_Nythix @ 2023-09-20 19:02:28


@[gghack_Nythix](/user/895690) 优先 at 一下题目管理志愿者吧
by 小粉兔 @ 2023-09-20 20:15:17


@[小粉兔](/user/10703) 好
by gghack_Nythix @ 2023-09-20 20:20:17


@[ShineEternal](/user/45475)
by gghack_Nythix @ 2023-09-20 20:21:48


|