Advertisement
SuitNdtie

Dictionary2

May 12th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int fac[10] = {1,1,2,6,24,120,720,5040,40320,362880};
  4.  
  5. int main()
  6. {
  7.     int T;
  8.     scanf("%d",&T);
  9.     for(int t = 1 ; t <= T ; t ++)
  10.     {
  11.         char str[11];
  12.         scanf("%s",str);
  13.         bool check[11];
  14.         for(int i = 0 ; i < 11 ; i ++){
  15.             check[i] = true;
  16.         }
  17.        
  18.         int ans = 0;
  19.         for(int i = 0 ; i < 9 ; i ++){
  20.             int value[11];
  21.             int cnt = 0;
  22.             for(int j = 0 ; j <= 8 ; j ++){
  23.                 if(check[j]){
  24.                     value[j] = cnt++;
  25.                 }
  26.             }
  27.             ans += value[str[i]-'a']*fac[9-i-1];
  28.             check[str[i]-'a'] = false;
  29.         }
  30.         printf("%d\n",ans+1);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement