poj3007

简单题

View Code
   
     
#include < iostream >
#include
< cstdio >
#include
< cstdlib >
#include
< cstring >
#include
< algorithm >
using namespace std;

#define maxn 200

char st[maxn], st1[maxn];
int n, ans;
char word[maxn * 100 ][maxn];

void ins( char * st)
{
for ( int i = 0 ; i < ans; i ++ )
if (strcmp(st, word[i]) == 0 )
return ;
strcpy(word[ans
++ ], st);
}

int main()
{
// freopen("t.txt", "r", stdin);
int t;
scanf(
" %d " , & t);
while (t -- )
{
scanf(
" %s " , st);
ans
= 0 ;
n
= strlen(st);
for ( int i = 0 ; i < n - 1 ; i ++ )
{
strcpy(st1, st);
ins(st1);

reverse(st1, st1
+ i + 1 );
ins(st1);

reverse(st1
+ i + 1 , st1 + n);
ins(st1);

reverse(st1, st1
+ i + 1 );
ins(st1);

reverse(st1, st1
+ n);
ins(st1);

reverse(st1, st1
+ n - i - 1 );
ins(st1);

reverse(st1, st1
+ n - i - 1 );
reverse(st1
+ n - i - 1 , st1 + n);
ins(st1);

reverse(st1, st1
+ n - i - 1 );
ins(st1);
}
printf(
" %d\n " , ans);
}
return 0 ;
}

你可能感兴趣的:(poj)