标签:
#include<iostream> #include<string> #include<math.h> using namespace std; /* string convertToTitle(int n) { string str1; int i=0; int a=n; while(1) { int pinf_i=pow(26.0,i); int pinf_ii=pow(26.0,i+1); int b; if(a<=pinf_ii) {b=a/pinf_i;str1.push_back(b+64);break;} if(a>pinf_ii) { if(a%pinf_ii==0) { str1.push_back(‘Z‘); a=a-26*pinf_i; } else { b=(a%pinf_ii)/pinf_i; str1.push_back(b+64); a=a-b*pinf_i; } i++; } } string str2; int N=str1.size(); while(N--) { str2.push_back(str1.back()); str1.pop_back(); } return str2; } */ string convertToTitle(int n) { string str1; while(n!=0) { n--; str1.push_back(n%26+65); n/=26; } string str2; int N=str1.size(); while(N--) { str2.push_back(str1.back()); str1.pop_back(); } return str2; } int main() { cout<<convertToTitle(703)<<endl; }
leetcode_168题——Excel Sheet Column Title(数学问题)
标签:
原文地址:http://www.cnblogs.com/yanliang12138/p/4535374.html