11192 - Group Reverse

Let's talk about algorithms!

Moderator: Board moderators

11192 - Group Reverse

Postby scofield » Tue Jan 31, 2012 4:02 pm

Hello, i solved the problem and tested with some sample inputs, the outputs are always right, but when submit i got Wrong Answer, i can't identify what's wrong in the code.
Could you please give me a help to check what's wrong?

Code: Select all
int main()
{
    unsigned char nbrGroups=48, lines=0, offset = 0x00, out_offset=0,
    outstr[100], chars, count, groupSize, i;
    string str;

    //number of groups valid between 0 and 9
    while((nbrGroups >= 48) && (nbrGroups <= 57) && (++lines < 11))
    {
        cin >> nbrGroups;
        cin >> str;
        offset=0;
        out_offset=0;

        if(nbrGroups != 48)
        {
            //calculate the group size
            for(count=0;str[count] != 0x00; count++);

            //check if the total length is multiple of nbrGroups
            if(count%(nbrGroups-48) == 0)
            {
                groupSize = count/(nbrGroups-48);

                //go throught the groups
                for(count=0;count<(nbrGroups-48);count++)
                {
                    //invert the group
                    for(i=offset+groupSize;i != offset ;i--)
                        outstr[out_offset++] = str[i-1];

                    //set the position to the next group
                    offset+=(groupSize);
                }

                outstr[out_offset] = 0x00;
                cout << outstr << endl;
            }
        }
    }

    return 0;
}



Thanks in advance.
scofield
New poster
 
Posts: 2
Joined: Tue Jan 31, 2012 3:20 am

Return to Algorithms

Who is online

Users browsing this forum: No registered users and 1 guest