#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
//A-Z:65-90 a-z: 97-122
using namespace std;
int getColumnNumber(char s[])
{
//特殊情况处理
if(s == nullptr) return -1;
int number = 0;
//统计长度
int i = 0;
while (s[i]!='\0')
{
//异常情况:不在范围,直接返回-1
if(!((s[i]>=65 && s[i]<=90) || (s[i]>=97 && s[i]<=122)))
return -1;
//小写转大写
if(s[i]>=97 && s[i]<=122)
s[i] -= 32;
i++;
}
//26进制换算
int j = 0;
while (i>0)
number += (s[--i] - 64)*pow(26, j++);
return number;
}
int main()
{
cout << getColumnNumber("AFA") << endl;
system("pause");
}
算法_EXCEL中 A表示第一列,B表示第二列...AA表示27列,AB表示28列,问随意一组字母是多少列
猜你喜欢
转载自blog.csdn.net/shyjhyp11/article/details/113727555
今日推荐
周排行