168. Excel Sheet Column Title

原文题目:

168. Excel Sheet Column Title

读题:

将整数转为EXCEL表格列标,实际上就是十进制转26进制

class Solution 
{
public:
	string convertToTitle(int n) 
	{
		string result ="";
		char apha[27]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		vector <int> v;
		int temp = n;
		int remain = 0;
		int i = 0;
		while(temp)
		{
			remain = temp%26;
			//处理26/52这种26倍数的边界
			if (remain ==0)
			{
				remain = 26;
				temp -= 1;
			}
			v.push_back(remain-1);
			temp = temp/26;
		}
		for (i = v.size()-1; i>=0;i--)
		{
			result += apha[v[i]];
		}
		return result;

	}
};

int main()
{
	Solution s;
	string result;
	int i = 0;
	result = s.convertToTitle(53);
	cout << result<<endl;
}

  

原文地址:https://www.cnblogs.com/xqn2017/p/8006812.html