|
|
вернуться в форумI got crash in test #23 Послано anhpnt 21 сен 2009 23:09 Is there something special in test #23? I got crash (access violation). Re: I got crash in test #23 I have WA in this test. It's my code: #include <iostream> #include <string> #include <algorithm> #define N 1111 using namespace std; string s; int n,d1[N],d2[N],k; int main(){ getline(cin,s); n=s.length(); for (int i=0;i<n;i++){ for (k=1;i-k>=0 && i+k<n;k++) if (s[i-k]!=s[i+k]) break; d1[i]=max(k-1,-1); } for (int i=1;i<n;i++){ if (s[i]!=s[i-1]){ d2[i]=-1; continue; } for (k=1;i-k-1>=0 && i+k<n;k++) if (s[i-k-1]!=s[i+k]) break; d2[i]=max(k-1,0); } int *k1=max_element(d1,d1+n),*k2=max_element(d2+1,d2+n); if (*k1>=*k2+1) for (int i=k1-d1-*k1;i<=k1-d1+*k1;i++) cout<<s[i]; else for (int i=k2-d2-*k2-1;i<=k2-d2+*k2;i++) cout<<s[i]; return 0; } Can I get this test? Re: I got crash in test #23 Послано zhqc 7 дек 2011 17:30 a you must output a Re: I got crash in test #23 Locally my program prints a. But have AC only if I add if (n==1){ cout<<s<<endl; return 0; } I found my mistake, but I don't know, why there are different answers on my computer and here. |
|
|