NYOJ 139 我排第几个
1 #include<iostream>
2 #include<string>
3 #include<memory.h>
4 using namespace std;
5 int Jc[13] = {0,1};
6 bool mark[13];
7 int main()
8 {
9 // freopen("in.txt","r",stdin);
10 char ch;
11 int k,i,j,s,t;
12 for(i = 2; i < 13; ++i)
13 Jc[i] = Jc[i-1] * i;
14 cin>>t;
15 while(t--)
16 {
17 s = 0;
18 memset(mark,0,sizeof(mark));
19 for(i=0; i<12; ++i)
20 {
21 cin>>ch;
22 k = 0;
23 int x = ch - 'a' + 1;
24 mark[x] = 1;
25 for(j = 1; j < x; ++j)
26 if(!mark[j])
27 ++k;
28 s += k * Jc[11-i];
29 }
30 cout<<s+1<<endl;
31 }
32 return 0;
33 }
2 #include<string>
3 #include<memory.h>
4 using namespace std;
5 int Jc[13] = {0,1};
6 bool mark[13];
7 int main()
8 {
9 // freopen("in.txt","r",stdin);
10 char ch;
11 int k,i,j,s,t;
12 for(i = 2; i < 13; ++i)
13 Jc[i] = Jc[i-1] * i;
14 cin>>t;
15 while(t--)
16 {
17 s = 0;
18 memset(mark,0,sizeof(mark));
19 for(i=0; i<12; ++i)
20 {
21 cin>>ch;
22 k = 0;
23 int x = ch - 'a' + 1;
24 mark[x] = 1;
25 for(j = 1; j < x; ++j)
26 if(!mark[j])
27 ++k;
28 s += k * Jc[11-i];
29 }
30 cout<<s+1<<endl;
31 }
32 return 0;
33 }