Problem:
Problem B: Organize Your Train part II

RJ Freight, a Japanese railroad company for freight operations
has recently constructed exchange lines at Hazawa, Yokohama.
The layout of the lines is shown in Figure B-1.

Figure B-1: Layout of the exchange lines

A freight train consists of 2 to 72 freight cars. There are 26
types of freight cars, which are denoted by 26 lowercase letters
from "a" to "z". The cars of the same type are indistinguishable from
each other, and each car's direction doesn't matter either.
Thus, a string of lowercase letters of length 2 to 72 is sufficient
to completely express the configuration of a train.

Upon arrival at the exchange lines, a train is divided into two
sub-trains at an arbitrary position (prior to entering the
storage lines). Each of the sub-trains may have its direction
reversed (using the reversal line). Finally, the two sub-trains
are connected in either order to form the final configuration.
Note that the reversal operation is optional for each of the
sub-trains.

For example, if the arrival configuration is "abcd", the train
is split into two sub-trains of either 3:1, 2:2 or 1:3 cars.
For each of the splitting, possible final configurations are
as follows ("+" indicates final concatenation position):

[3:1]
abc+d cba+d d+abc d+cba
[2:2]
ab+cd ab+dc ba+cd ba+dc cd+ab cd+ba dc+ab dc+ba
[1:3]
a+bcd a+dcb bcd+a dcb+a

Excluding duplicates, 12 distinct configurations are possible.

Given an arrival configuration, answer
the number of distinct configurations which can be
constructed using the exchange lines described above.

Input

The entire input looks like the following.

the number of datasets = m

1st dataset

2nd dataset

...

m-th dataset

Each dataset represents an arriving train, and is a string of
2 to 72 lowercase letters in an input line.

Output

For each dataset, output the number of possible train configurations
in a line. No other characters should appear in the output.

Sample Input

4
aa
abba
abcd
abcde

Output for the Sample Input

1
6
12
18

Solution in C (judge verdict: Wrong Answer)

#include<stdio.h>
#include<string.h>


char *reverse(char *s) {

	int i;
	char answer[strlen(s)];
	int length = strlen(s);

	memset(answer,'\0',sizeof(char));

	for(i=0;i<=strlen(s)-1;i++)
		answer[i]=s[strlen(s)-1-i];

	strcpy(s,answer);
	s[length] = '\0';
	return s;
}

int main() {

	int m;
	char c[73];
	char s1[73],s2[73];
	char temp1[73],temp2[73];
	char s1_rev[73],s2_rev[73];
	char A[600][73];
	int a,i,j,k,l,x;
	int A_max;
	int answer;
	int length;

	scanf("%d\n",&m);

	//???????????????????????§?¨????????§?
	for(a=0;a<m;a++) {

		answer=0; //??????;
		fgets(c,sizeof(c),stdin);
		c[strlen(c)-1]='\0';
		length = strlen(c);

		for(i=0;i<600;i++)
			for(j=0;j<73;j++)
				A[i][j]='\0';

		//???????????????
		for(j=1;j<strlen(c);j++) {
			for(x=1;x<=8;x++){
				memset(s1,'\0',sizeof(char));
				memset(s2,'\0',sizeof(char));
				memset(temp1,'\0',sizeof(char));
				memset(temp2,'\0',sizeof(char));
				memset(s1_rev,'\0',sizeof(char));
				memset(s2_rev,'\0',sizeof(char));

				strncpy(s1,c,j);
				strncpy(s2,c+j,strlen(c)-j+1);
				s1[j]='\0';
				s2[strlen(c)-j+1]='\0';
				strcpy(temp1,s1);
				strcpy(temp2,s2);
				strcpy(s1_rev,reverse(temp1));
				strcpy(s2_rev,reverse(temp2));

				switch(x) {
				case 1:
					//s1,s2????????????(c)
					strcpy(A[8*(j-1)],c);
					break;
				case 2:
					//s1???????????¢
					strcpy(A[8*(j-1)+1],strcat(s1_rev,s2));
					break;
				case 3:
					//s2???????????¢
					strcpy(A[8*(j-1)+2],strcat(s1,s2_rev));
					break;
				case 4:
					//s1,s2???????????¢
					strcpy(A[8*(j-1)+3],strcat(s1_rev,s2_rev));
					break;
					//????????????s1,s2?????¢
				case 5:
					//s1.s2????????????
					strcpy(A[8*(j-1)+4], strcat(s2,s1));
					break;
					//s1???????????¢
				case 6:
					strcpy(A[8*(j-1)+5],strcat(s2_rev,s1));
					break;
					//s2???????????¢
				case 7:
					strcpy(A[8*(j-1)+6],strcat(s2,s1_rev));
					break;
				case 8:
					//s1,s2???????????¢
					strcpy(A[8*(j-1)+7],strcat(s2_rev,s1_rev));
					break;
				}
			}
		}
		A_max=8*(strlen(c)-1);

		for(k=0;k<A_max;k++) {
			if(k==0)
				answer++;
			else {
				for(l=0;l<k;l++) {
					if(!strcmp(A[l],A[k]))
						break;
					else if(l==k-1) {
						//printf("%d\n",k);
						answer++;
					}
				}
			}

		}
		printf("%d\n",answer);
	}

	return 0;
}