I want to know why it happens with me many a times that my solutions give right output but I still get a WA ?
For example , for this question CodeChef: Practical coding for everyone . My solution was giving the right output , but a WA .
I can give the link to my solution here , if allowed .
as they say in the mail â⌠please do not consider the given test cases as the âsoleâ test casesâŚâ
most of the times it is advisable to have your own test case which is âmanuallyâ worked out as a reference. depending on the complexity of the test cases you generate, less is the number you have to generate.
as far as coding is consider, coincidences are pretty common thing wherein you end up âseeingâ the âcorrectâ answer rather than actually âgettingâ the âcorrectâ answer!
@ishitva the line in your code
char msg[200];
should be
char msg[201];
one more for the â\0â character try changing this i hope u will get ACâŚ
@amitupadhyay is correct, your array size is the culprit.
SPOJ TOANDFRO
*Note: the scanf(â%d\nâ, &t) part in the above code.
PRISON BREAK
http://www.codechef.com/viewsolution/1830845
This was my code during the contest.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
using namespace std;
const int SIZ = 210;
int main() {
int t;
scanf("%d", &t);
char s[SIZ];
while(t--) {
int l, col, row;
scanf("%d\n", &col);
for(l=0; l<SIZ; l++) {
scanf("%c", &s[l]);
if(s[l] == '\n') {
l--;
break;
}
}
//cout<<"s "<<endl;
/*for(int i=0; i<=l; i++)
printf("%c", s[i]);
cout<<endl;*/
row = (l+1) / col;
//cout<<"row "<<row<<" col "<<col<<endl;
char s2[row][col];
char s3[row][col];
int k=0;
for(int i=0; i<row; i++) {
for(int j=0; j<col, k<=l; j++) {
s2[i][j] = s[k];
k++;
}
}
//cout<<"s2 "<<endl;
/*for(int i=0; i<row; i++) {
for(int j=0; j<col; j++) {
printf("%c", s2[i][j]);
}
cout<<endl;
}
cout<<endl;*/
for(int i=0; i<row; i++) {
for(int j=0; j<col; j++) {
if(i%2!=0) {
s3[i][j] = s2[i][col-1-j];
}
else {
s3[i][j] = s2[i][j];
}
}
}
//cout<<"s3 "<<endl;
for(int i=0; i<col; i++) {
for(int j=0; j<row; j++) {
printf("%c", s3[j][i]);
}
//cout<<endl;
}
cout<<endl;
}
return 0;
}
@avinrox I tried SPOJ.com - Problem TOANDFRO I tried my solution at SPOJ after modifying it to receive input until a 0 is entered , but got an AC there.
@amitupadhyay , Where to submit the solution now ? the submissions have closed. I am unable to find it in the practice section .
Okay. But my previous solution gave an AC at SPOJ after modifying it to take input until a 0 is entered
http://ideone.com/AX4uT4 for
SPOJ.com - Problem TOANDFRO ?
SPOJ do not cover all the corner test cases⌠go to ideone.com input a string of length of 200⌠and see u will get WAâŚ
talking of SPOJ it also have a FLIPCOIN question as on codechef i did get an AC here but still having WA here on codechef⌠testing s intense in codechef
Try to look for edge cases.
I want to know why it happens with me many a times that my solutions give right output but I still get a WA ?
. My solution was giving the right output , but a WA