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