nyoj 我排第几个
http://acm.nyist.net/JudgeOnline/problem.php?pid=139
View Code
1 #include<stdio.h> 2 #include<string.h> 3 int jiecheng(int x) 4 { 5 int jie=1; 6 for(int i=2;i<=x;i++) 7 jie*=i; 8 return jie; 9 } 10 int main() 11 { 12 int t; 13 int len; 14 char ch; 15 char str[13]; 16 scanf("%d",&t); 17 while(t--) 18 { 19 scanf("%s",str); 20 len=strlen(str); 21 int sum=0; 22 for(int i=len-1;i>=0;i--) 23 { 24 ch=str[i]; 25 int count=0; 26 for(int j=len-1;j>i;j--) 27 { 28 if(ch>str[j]) count++; 29 } 30 sum+=count*jiecheng(len-1-i); 31 //printf("%d\n",sum); 32 } 33 printf("%d\n",sum+1); 34 } 35 }