【Codeforces 1B】Spreadsheets
【链接】 我是链接,点我呀:)
【题意】
【题解】
转换方法说实话特别恶心>_< int转string 得像数位DP一样一位一位地确定每一位是啥. 具体的 1位数可以表示16个数字 2位数又可以表示16*16个数字 根据这个算出来int对应的字符串是多少位数的 然后再一点一点地试出来每一位是多少即可【代码】
import java.io.*;
import java.util.*;
public class Main {
static InputReader in;
static PrintWriter out;
public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
}
static int N = (int)1e6;
static class Task{
boolean isdigit(char key) {
if (key>='0' && key<='9') return true;
else return false;
}
int strtoint(String s) {
int temp = 1;
int cur = 0;
int len = s.length();
for (int i = len-1;i >= 0;i--) {
cur = cur + temp*(s.charAt(i)-'A'+1);
temp = temp*26;
}
return cur;
}
String inttostr(int col) {
StringBuilder sb = new StringBuilder();
int cur = 26;
int cnt = 1;
while (col>cur) {
col-=cur;
cur = cur*26;
cnt++;
}
for (int i = 1;i <= cnt;i++) {
for (int j = 26;j>=1;j--)
if ((j-1)*(cur/26)<col) {
col-=(j-1)*cur/26;
char key = (char)(j+'A'-1);
sb = sb.append(key);
cur/=26;
break;
}
}
return sb.toString();
}
public void solve(InputReader in,PrintWriter out) {
int n;
n = in.nextInt();
int []num = new int[2];
for (int i = 1;i <= n;i++) {
String s = in.next();
int cnt = 0;
int len = s.length();
int fir = 0;
for (int j = 0;j < len;j++) {
if (isdigit(s.charAt(j))) {
int k = j;
fir = j;
while (k+1<len && isdigit(s.charAt(k+1)) ) k++;
//j..k全是数字
int temp = 0;
for (int l = j;l <= k;l++)
temp = temp*10+s.charAt(l)-'0';
num[cnt++] = temp;
j = k;
}
}
if (cnt==1) {
//AB12
int rows = num[0];
int col = strtoint(s.substring(0, fir));
out.println("R"+rows+"C"+col);
}else {
int rows = num[0];int cols = num[1];
String strcols = inttostr(cols);
out.println(strcols+rows);
}
}
}
}
static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer;
public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
}
public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}