1 / 5
Jul 2008

I'm using the inputs and outputs from http://acm.ashland.edu/2004/problem-set.html
input: http://acm.ashland.edu/2004/Problem-Set/Data/G.dat
output: http://acm.ashland.edu/2004/Problem-Set/Data/G.diff
all my inputs and outputs seem to match up but i still get a WA. The only thing i can think of is that its a problem with the zero. What does the online judge want to happen with the input of "0"? Any help is greatly appreciated.
here is my code:

import sys
def main():
    num_input = int(raw_input())
    string_input = list(raw_input())
    row_list = process(num_input, string_input)
    display(row_list, num_input)
def process(  columns, string ):
    num_rows = len(string)/columns
    odd_even = 0
    j = ""
    row_list = []
    for row in range(num_rows):
        row_add = []
        for letter in range(columns):
            row_add.append(string.pop(0))
        if odd_even == 0: odd_even =1
        elif odd_even == 1:
            row_add.reverse()
            odd_even = 0
        row_list.append(j.join(row_add))
    return row_list
def display(rows, columns):
    shitstring = ""
    for index in range(columns):
        for row in range(len(rows)):
            sys.stdout.write(rows[row][index])
try:
    main()
except(ZeroDivisionError):
    pass
  • created

    Jul '08
  • last reply

    Oct '10
  • 4

    replies

  • 164

    views

  • 4

    users

  • 3

    links

It looks to me like your program is only reading in the first test case in the input. It should continue reading in and processing test cases until it reads a 0 for the number of columns, and then it should stop.

Oh god, now i feel like an idiot smile. I always manage to overlook something small like that. thanks for pointing that out!

2 years later

Rather than make a whole entire new thread, I thought I would post to this one: Ive ran through the inputs and outputs at the ACM website. I get the correct answers for output, but SPOJ is giving me a wrong answer. Any extra eyes would be appreciated.

#include<stdio.h>
#include<string.h>
#define MAX_LEN 200
#define MAX_ROW 6
void decrypt(char* crypted_text, unsigned int columns);
int main(void)
{
    unsigned int numCols;
    scanf("%d", &numCols);
while(numCols != 0)
{
    char toDecrypt[MAX_LEN];

    scanf("%s", toDecrypt);
    decrypt(toDecrypt, numCols);
    scanf("%d", &numCols);
}
  return 0;
}
void decrypt(char* crypted_text, unsigned int columns)
{
    auto int pos, index, aPos;
    auto int len = strlen(crypted_text);
    for(pos = 0; pos < columns; pos++)
{
    printf("%c", crypted_text[pos]);
    index = 1;
    while(index <= (MAX_ROW / 2))
    {
        aPos = ((columns * 2 * index) - (pos + 1));
        if (aPos <= len)
            printf("%c", crypted_text[aPos]);
        aPos = ((columns * 2 * index) + pos);
        if (aPos <= len)
        printf("%c", crypted_text[aPos]);
        index++;
    }

}
puts("");
return;
}

Here is a test input file ive compiled, and my output:
input:

    5
    toioynnkpheleaigshareconhtomesnlewx
    3
    ttyohhieneesiaabss
    3
    wkgxiornx
    4
    hneilvaelmitoneloihnhasmykmh
    6
    toioywhnnkpheleaiatgshareconhthtomesnlewxe
    6
    itrythisforfun
    5
    toioynnkpheleaigshareconhtomesnlewx
    3
    optioncnmeaeutq
    20
    aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbcccccccccccccccccccc
    15
    abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabccxxxxx
    4
    abcddcbaabcxxcbaabcx
    0

and my output:

    theresnoplacelikehomeonasnowynightx
    thisistheeasyoneab
    workingxx
    hellomynameiskevinhamiltonhh
    theresnoplacelikehomeonasnowynightxwhatthe
    ifutrnroyftshi
    theresnoplacelikehomeonasnowynightx
    onceuponattimeq
    abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc
    acacacabbbbbbbcacacacacacacabbbbbbbcacacacacacacabbbbbbbcacacacacacacabbbbbbbcacacacacacacabbbbbbbcacacac
    aaaaabbbbbcccccddxxx

Good idea. But this is the forum's Python section ...