链接:
https://www.nowcoder.com/questionTerminal/2313251da21e4f6390eaf8a4539ef41d?pos=6&mutiTagIds=589&orderByHotValue=2
来源:牛客网
来源:牛客网
序列seq=[a,b,…,z,aa,ab,…,az,ba,bb,…,bz,…,za,zb,…,zz,aaa,…]类似于excel的字母序排列,任意给一字符串 s=[a-z]+(由a-z字符串组成的任意长度字符串),请问s是序列seq的第几个字符串。
#include <iostream> #include <cstring> using namespace std; int a[100]; int main() { string s; cin>>s; int result=0; for(int i=0;i<s.length();i++){ result=(result*26+(s[i]-'a'+1)); } cout<<result; return 0; }
PS:26进制,厉害,result直接是原来的乘以26,加上当前字母的序号。