题目:序列 seq=[a,b,…,z,aa,ab,…,az,ba,bb,…,bz,…,za,zb,…,zz,aaa,…]类似于excel的字母序排列,任意给一字符串 s=[a-z]+(由a-z字符串组成的任意长度字符串),请问s是序列seq的第几个字符串。
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
char s[26] = { 'a', 'b', 'c', 'd', 'e' ,'f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char str[100];
cout << "获取字符串:";
gets(str);
int len = strlen(str);
int count = len-1;
int re = 0;
for (int i = 0; i < len; ++i)
{
for (int j = 0; j < 26; ++j)
{
if (str[i] == s[j])
{
re += pow(26, count) * (j+1);
count--;
}
}
}
cout << "返回结果:re=" << re << endl;
return 0;
}