Problem 1001 求帮看代码错在哪?

onlyAzha | 2015-04-11 21:10:38Author
#include <stdio.h> #include <iostream> #include <cstring> #include <algorithm> using namespace std; char str[1100]={0}; int a[1100]={0}; int judge() { for(int i=0,j=strlen(str)-1;i<j;i++,j--) if(str[i]!=str[j]) return 0; return 1; } int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int n; while(scanf("%d",&n)!=EOF) { memset(str,0,sizeof(str)); memset(a,0,sizeof(a)); int c=0,flag=0,flag1=0; scanf("%s",str); for(int i=0;i<n;i++) if(str[i]=='?') { flag=1; str[i]='a'; a[c++]=i; } if(flag) { if(judge()&&c) str[a[c-1]]='b'; c--; while(judge()&&c) { str[a[c]]='a'; str[a[c-1]]='b'; c--; } if(judge()&&n>=2) printf("QwQ\n"); else printf("%s\n",str); } else printf("QwQ\n"); } return 0; }
onlyAzha | 2015-04-11 21:11:05# 1
#include <stdio.h> #include <iostream> #include <cstring> #include <algorithm> using namespace std; char str[1100]={0}; int a[1100]={0}; int judge() { for(int i=0,j=strlen(str)-1;i<j;i++,j--) if(str[i]!=str[j]) return 0; return 1; } int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int n; while(scanf("%d",&n)!=EOF) { memset(str,0,sizeof(str)); memset(a,0,sizeof(a)); int c=0,flag=0,flag1=0; scanf("%s",str); for(int i=0;i<n;i++) if(str[i]=='?') { flag=1; str[i]='a'; a[c++]=i; } if(flag) { if(judge()&&c) str[a[c-1]]='b'; c--; while(judge()&&c) { str[a[c]]='a'; str[a[c-1]]='b'; c--; } if(judge()&&n>=2) printf("QwQ\n"); else printf("%s\n",str); } else printf("QwQ\n"); } return 0; }
onlyAzha | 2015-04-11 21:12:44# 2
http://paste.ubuntu.com/10800242/ 这是代码