标签:ace mod leo += == 需要 字符 整数 一个
Input
Output
输出n行,每行是对应的位置的转化结果。
Sample Input
Sample Output
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<stack> #include<cstdlib> #include<queue> #include<set> #include<string.h> #include<vector> #include<deque> #include<map> using namespace std; #define INF 0x3f3f3f3f #define eps 1e-10 #define bug printf("*********\n") #define debug(x) cout<<#x"=["<<x<<"]" <<endl typedef long long LL; typedef long long ll; const int MAXN = 1e6 + 5; const int mod = 998244353; bool is(char a) { if(‘A‘ <= a && a <= ‘Z‘) return true; return false; } int check(char *s) { int len = strlen(s); int ans = 0,pos1 = -1,pos2 = -1; for(int i = 0 ;i < len; i++) { if(is(s[i]) && s[i] != ‘R‘ && s[i] != ‘C‘) { ans++; continue; } if(s[i] == ‘R‘) { ans ++; pos1 = i; } if(s[i] == ‘C‘) { ans++; pos2 = i; } } if(ans == 2 && pos1 != -1 && pos2 != -1 && pos2 - pos1 > 1) return 1; return 2; } //将一个数转换为A - Z的进制,比如3 -> C 34 -> AH 123 -> DS void K(int n) { if(n>26) K((n-1)/26); printf("%c",(n-1)%26+‘A‘); } int main() { int n; cin >> n; while(n--) { char s[MAXN]; scanf("%s",s); int flag = check(s); //debug(flag); if(flag == 1) { int len = strlen(s); int pos1 = -1,pos2 = -1; for(int i = 0 ;i < len; i++) { if(s[i] == ‘R‘) { pos1 = i; } if(s[i] == ‘C‘) { pos2 = i; } } int p1 = 0,p2 = 0; for(int i = pos1 + 1; i < pos2; i++) { p1 *= 10; p1 += (s[i] - ‘0‘); } for(int i = pos2 + 1; i < len; i++) { p2 *= 10; p2 += (s[i] - ‘0‘); } char ch = ‘A‘; K(p2); printf("%d\n",p1); } else { int p1 = 0,p2 = 0; int len = strlen(s); int i; for(i = 0; i < len; i++) { if(is(s[i])) { p1 *= 26; p1 += s[i] - ‘A‘ + 1; } else break; } for(i ; i < len ; i++) { p2 *= 10; p2 += s[i] - ‘0‘; } printf("R%dC%d\n",p2,p1); } } }
B - Spreadsheets CodeForces - 1B
标签:ace mod leo += == 需要 字符 整数 一个
原文地址:https://www.cnblogs.com/smallhester/p/11360907.html