WA in "To and Fro" (PD33)

#include <bits/stdc++.h>
using namespace std;

int main() {
int n,len,r;
string str;
cin>>n;
while(n!=0)
{
    cin>>str;
    len = str.length();
    r = len/n;
    char a[len][r];
    int k=0;
    for(int i=0;i<r;i++)
    {
        if(i%2==0)
        {
            for(int j=0;j<n;j++)
                a[i][j] = str[k++];    
        }
        
        else
        {
            for(int j=n-1;j>=0;j--)
                a[i][j] = str[k++];
        }

}

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<r;j++)
            cout<<a[j][i];
    }
    
    cout<<endl;
    cin>>n;
}
return 0;

}

the custom inputs are giving the correct results though

link to solution : https://www.codechef.com/viewsolution/28576122Preformatted text

Please either format your code or link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Note that this isn’t a link to your submisson; this is, though :slight_smile:

2 Likes

yeah, edited it

1 Like

please help. why is it giving the wrong answer

Consider the testcase:

5                                                       
egaacdfadgbagfg
0

I did a really stupid mistake. Instead of taking the char[r][n], I took it as char[len][n]. And that’s really embarrassing. Now it has been accepted.

1 Like