Smiling & Weeping
---- 他未对我好半分,偏巧这感情疯长似野草
思路:与新三进制2思路相似,转化为纯26进制,然后往前遍历创造出符合题目要求的
Talk is cheap , show me the code
1 #include<bits/stdc++.h> 2 using namespace std; 3 int t; 4 // 1代表 R12C12形式 , 2代表BC12的形式 5 inline int get_form(char *s){ 6 bool flag1 = false , flag2 = false; 7 for(int i = 0; i < strlen(s); i++){ 8 if(isdigit(s[i])) flag1 = true; 9 if(flag1 && !isdigit(s[i])){ 10 return 1; 11 } 12 } 13 return 2; 14 } 15 int main() 16 { 17 scanf("%d",&t); 18 while(t--){ 19 char s[30]; 20 scanf("%s",s); 21 int form = get_form(s); 22 if(form == 1){ 23 bool flag = true; 24 int numr=0 , numc=0 , len=0; 25 for(int i = 1; i < strlen(s); i++){ 26 if(s[i]>='0' && s[i]<='9' && flag) numr = numr*10 + s[i]-'0'; 27 if(s[i] == 'C'){ 28 flag = false; 29 continue; 30 } 31 if(!flag) numc = numc*10 + s[i]-'0'; 32 } 33 int ans[20]; 34 memset(ans , 63 ,sizeof(ans)); 35 while(numc){ 36 ans[++len] = numc%26; 37 numc /= 26; 38 } 39 for(int i = len-1; i >= 1; i--){ 40 if(ans[i] == 0){ 41 ans[i+1]--; 42 ans[i] += 26; 43 } 44 } 45 //cout << len << " "; 46 for(int i = len-1; i >= 1; i--){ 47 if(ans[i] == 0){ 48 ans[i+1]--; 49 ans[i] += 26; 50 } 51 } 52 for(int i = len-1; i >= 1; i--){ 53 if(ans[i] == 0){ 54 ans[i+1]--; 55 ans[i] += 26; 56 } 57 } 58 if(ans[len] == 0) len--; 59 for(int i = len; i >= 1; i--) 60 printf("%c",ans[i]+'A'-1); 61 printf("%d\n",numr); 62 } 63 else{ 64 int numc=0 , numr=0; 65 bool flag = true; 66 for(int i = 0; i < strlen(s); i++){ 67 if(flag && !isdigit(s[i])) numc = numc*26+s[i]-'A'+1; 68 if(s[i]<='9' && s[i]>='0' && flag) flag = false; 69 if(!flag) numr = numr*10+s[i]-'0'; 70 } 71 printf("R%dC%d\n",numr,numc); 72 } 73 } 74 return 0; 75 }
我裁一段星河以赠你,好教你不逊色这人间错落烟火
文章到此结束,我们下次再见
标签:26,numr,int,excel,烦恼,--,flag,ans From: https://www.cnblogs.com/smiling-weeping-zhr/p/17649845.html