/* reverse_nums.c - by Daniel Rice, 11/91.
   Permission is granted for any use of this code. */

/* For those who are not planning to display these files right-to-left,
   the book, chapter and verse numbers are 'backwards.'
   This program reverses them.  There may be some bugs in the treatment
   of end-of-file, but you can just use an editor to clean up the end
   of the output file. */

#include <stdio.h>

int
reverse (s)
char *s;

{
	if (strlen(s) == 1)
		return s[0] - '0';
	else if (strlen(s) == 2)
		return 10 *(s[1] - '0') + (s[0] - '0'); 
	else if (strlen(s) == 3)
		return 100 *(s[2] - '0') + 10*(s[1] - '0') + (s[0] - '0');
	else {
		fprintf (stderr, "Too big!\n");
		exit (1);
	}
}

main ()

{
	int c;
	char book[5], chapter[5], verse[5];

	while ((c = getchar()) != EOF) {
		ungetc (c, stdin);
		if (scanf ("%[0-9] %[0-9] %[0-9]", book, chapter, verse) != EOF) {
			printf ("%d %d %d",reverse(book),reverse(chapter),reverse(verse));
			while ((c = getchar()) != '\n' && c != EOF)
				putc (c, stdout);
		}
		putc ('\n', stdout);
	}
}
