标签:style blog class code java ext
//#define LOCAL #include<cstdio> #include<cstring> int const MAX_N=12; int const a[MAX_N]={0,1, 2 ,6 ,24 ,120 ,720 ,5040 ,40320 ,362880 ,3628800 ,39916800}; char c[MAX_N]; long solve(char* ch) { long sum=0; int i,j,con; for(i=0;i<MAX_N;i++) { con=0; for(j=i+1;j<MAX_N;j++) { if(ch[i]>ch[j]) con++; } sum=sum+con*a[MAX_N-i-1]; } return (sum+1); } int main() { #ifdef LOCAL freopen("Input","r",stdin); freopen("output1","w",stdout); #endif int N; scanf("%d\n",&N); while(N--) { gets(c); printf("%ld\n",solve(c)); } return 0; }
标签:style blog class code java ext
原文地址:http://www.cnblogs.com/jianfengyun/p/3719551.html