标签:
Related toquestion Excel Sheet Column Title
Given a columntitle as appear in an Excel sheet, return its corresponding column number.
For example:
A-> 1
B-> 2
C-> 3
...
Z-> 26
AA -> 27
AB -> 28
#pragma once
#include<queue>
#include<iostream>
using namespace std;
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
int titleToNumber(string s) {
char* p = (char*)s.c_str();
int sum = 0;
while (*p)
{
sum *= 26;
sum += *p - 'A' + 1;
p++;
}
return sum;
}
void main()
{
cout << titleToNumber("AB") << endl;
system("pause");
}
标签:
原文地址:http://blog.csdn.net/hgqqtql/article/details/43278743