Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int fac[10] = {1,1,2,6,24,120,720,5040,40320,362880};
- int main()
- {
- int T;
- scanf("%d",&T);
- for(int t = 1 ; t <= T ; t ++)
- {
- char str[11];
- scanf("%s",str);
- bool check[11];
- for(int i = 0 ; i < 11 ; i ++){
- check[i] = true;
- }
- int ans = 0;
- for(int i = 0 ; i < 9 ; i ++){
- int value[11];
- int cnt = 0;
- for(int j = 0 ; j <= 8 ; j ++){
- if(check[j]){
- value[j] = cnt++;
- }
- }
- ans += value[str[i]-'a']*fac[9-i-1];
- check[str[i]-'a'] = false;
- }
- printf("%d\n",ans+1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement