- #include <iostream>
- #include <string>
- using namespace std;
- int ff(int ii,int k)
- {
- int sum = 0;
- if( k <= 1) return 1;
- else{
- for(int m = ii+1; m <= 26; m++)
- {
- sum += ff(m,k-1);
- }
- return sum;
- }
- }
- int gg(int k)
- {
- int ss = 0;
- for(int jj = 1; jj <= 26; jj++)
- {
- ss += ff(jj,k);
- }
- return ss;
- }
- int main()
- {
- int pc = 0;
- int caseNum = 1;
- //cin>>caseNum;
- int *pResult = new int [caseNum];
- for(int i = 0; i < caseNum; i++)
- pResult[i] = 0;
- while( pc < caseNum )
- {
- int no = 0;
- int len = 0;
- string str = "";
- cin>>str;
- len = str.size();
- const char* pstr = str.c_str();
- if( len <= 1 )
- {
- pResult[pc] = int(*(pstr)) - 96;
- }
- else{
- int oldNo;
- if( *(pstr) == 1) oldNo = 1;
- else{
- oldNo = 0;
- }
- for(int i = 1; i <= len; i++)
- {
- no = int(*(pstr+i-1)) - 96;
- for(int j = oldNo+1; j < no; j++)
- {
- pResult[pc] += ff(j,len-i+1);
- }
- oldNo = no;
- }
- pResult[pc] += 1;
- for(int i = 1; i <= len-1; i++)
- {
- pResult[pc] += gg(i);
- }
- }
- pc++;
- }
- for(int i = 0; i < caseNum; i++)
- cout<<pResult[i]<<endl;
- delete []pResult;
- return 0;
- }
字典序问题
最新推荐文章于 2020-11-12 19:10:22 发布