Sort a Scrambled Itinerary

This algorithm problem is from Google Code Jam. Here is the description of the problem.

Once upon a day, Mary bought a one-way ticket from somewhere to somewhere with some flight transfers.
For example: SFO->DFW DFW->JFK JFK->MIA MIA->ORD.
Obviously, transfer flights at a city twice or more doesn’t make any sense. So Mary will not do that.
Unfortunately, after she received the tickets, she messed up the tickets and she forgot the order of the ticket.
Help Mary rearrange the tickets to make the tickets in correct order.

Input
The first line contains the number of test cases T, after which T cases follow.
For each case, it starts with an integer N. There are N flight tickets follow.
Each of the next 2 lines contains the source and destination of a flight ticket.

Output
For each test case, output one line containing “Case #x: itinerary”, where x is the test case number (starting from 1) and itinerary is sorted list of flight tickets which represents the actual itinerary. Each flight segment in the itinerary should be outputted as pair of source-destination airport codes.

Limits

1 ≤ T ≤ 100.
For each case, the input tickets are messed up from an entire itinerary bought by Mary. In other words, it’s ensured can be recovered to a valid itinerary.
1 ≤ N ≤ 10^4.
(The segment for second case in sample can be seen as below) MIA-ORD, DFW-JFK, SFO-DFW, JFK-MIA

Sample : 

Input
2
1
SFO
DFW
4
MIA
ORD
DFW
JFK
SFO
DFW
JFK
MIA

Output
Case #1: SFO-DFW
Case #2: SFO-DFW DFW-JFK JFK-MIA MIA-ORD

Here is my solution code. I have stored all destinations (as integer) in array element of departures (as integer).
First, we find a starting airport, which is marked as iDest = 0.  And recursively print departure-destination pairs.

/*
 ============================================================================
 Name        : CodeJam-ScrambledItinerary.c
 Author      : Elmurod Talipov
 Description : Problem C. Sort a scrambled itinerary
 ============================================================================
 */

#define  MAXCOM 	  (26*26*26 + 26*26 + 26+1)
#include <stdio.h>

int  N, iPair[MAXCOM];
char iDst[MAXCOM];
char iName[MAXCOM][4];

int main(void)
{
	int T, tc;
	int i, s, d;
	char STR[10];

	//freopen("input.txt", "r", stdin);
	scanf("%d", &T);
	for (tc = 1; tc <= T; tc++)
	{
		for (i = 0; i < MAXCOM; i++)
		{
			iPair[i] = -1;
			iDst[i] = 0;
		}

		scanf("%d", &N);
		for (i = 0; i < N; i++)
		{
			scanf("%s", STR);
			s = (STR[0] - 'A')*26*26 +  (STR[1] - 'A')*26 + (STR[2] - 'A');
			iName[s][0] = STR[0];
			iName[s][1] = STR[1];
			iName[s][2] = STR[2];
			iName[s][3] = '\0';

			scanf("%s", STR);
			d = (STR[0] - 'A')*26*26 +  (STR[1] - 'A')*26 + (STR[2] - 'A');
			iName[d][0] = STR[0];
			iName[d][1] = STR[1];
			iName[d][2] = STR[2];
			iName[d][3] = '\0';

			iPair[s] = d;
			iDst[d] = 1;
		}

		for (i=0;i<MAXCOM;i++)
			if ((iPair[i] != -1) && (iDst[i] == 0))
			{
				s = i;
				break;
			}

		printf ("Case #%d:", tc);
		while (N > 0)
		{
			d = iPair[s];
			printf(" %s-%s", iName[s], iName[d]);
			s = d;
			N--;
		}
		printf("\n");
	}

	return 0;
}