I row a few time limit: 1000 ms | Memory limit: 65535 KB Difficulty: 3 description
There is now a "abcdefghijkl" of 12 characters, arranged in all of its permutations in a dictionary order, giving any sort of arrangement, saying how small the arrangement is in all permutations. Enter the first row has an integer n (0<n<=10000);
Then there are n rows, each row is an arrangement, the output output is an integer m, a row, and the M is arranged in the first few; sample input
3
abcdefghijkl
Hgebkflacdji
Gfkedhjblcia
Sample output
1
302715242
260726926
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h >
using namespace std;
int main ()
{
int n;
Char a[10005],b[10005];
int Len;
CIN >> N;
for (int i = 0; i < n; i++)
{
long sum = 0;
scanf ("%s", a);
Len = strlen (a);
for (int j = 0; J < len-1;j++)
{
strcpy (b,a);
Sort (&b[j],b+len);
int k = 0;
for (; K + J < Len; k++)
if (a[j]==b[k+j]) break;
if (k + j < len) sum = (sum+k) * (LEN-1-J);
}
cout << sum + 1 << endl;
}
return 0;
}