Created
December 9, 2012 19:46
-
-
Save Koronen/4246693 to your computer and use it in GitHub Desktop.
encodedmessage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TOPSECRET | |
RosesAreRedVioletsAreBlue | |
SquaresMayBeEven |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 | |
RSTEEOTCP | |
eedARBtVrolsiesuAoReerles | |
EarSvyeqeBsuneMa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <math.h> | |
#define BUFFER_SIZE (10001) | |
unsigned int transform(unsigned int n, unsigned int row_length) | |
{ | |
unsigned int input_row = n / row_length; | |
unsigned int input_col = n % row_length; | |
unsigned int output_row = row_length - input_col - 1; | |
unsigned int output_col = input_row; | |
return output_row * row_length + output_col; | |
} | |
int main(int argc, char ** argv) | |
{ | |
unsigned int number_of_test_cases; | |
scanf("%i", &number_of_test_cases); | |
int i; | |
for(i = 0; i < number_of_test_cases; ++i) | |
{ | |
char input_buffer[BUFFER_SIZE]; | |
scanf("%s", input_buffer); | |
unsigned int input_length = strlen(input_buffer); | |
char output_buffer[input_length+1]; | |
unsigned int row_length = (int)floor(sqrt(input_length)); | |
int j; | |
for(j = 0; j < input_length; ++j) | |
{ | |
output_buffer[transform(j, row_length)] = input_buffer[j]; | |
} | |
output_buffer[input_length] = 0; | |
printf("%s\n", output_buffer); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C=gcc | |
C_FLAGS=-g -Wall -O3 | |
.PHONY: test submit clean | |
default: test | |
test: encodedmessage | |
./encodedmessage < E.in | diff E.ans - | |
encodedmessage: encodedmessage.c | |
$(C) $(C_FLAGS) $^ -o $@ -lm | |
submit: | |
kattis -f -p encodedmessage encodedmessage.c | |
clean: | |
rm -f encodedmessage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment