【Codeforces 1B】Spreadsheets
【链接】 我是链接,点我呀:)
【题意】
A~Z分别对应了1~26
AA是27依次类推
让你完成双向的转换
【题解】
转换方法说实话特别恶心>_
【代码】
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());
}
}
}
【Codeforces 1B】Spreadsheets的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- bzoj3663
几何+lis 很巧妙.直接做很困难,那么我们转化一下,把每个点能看见的圆弧画出来.只有这些圆弧相交时才满足条件. 那么也就是找出圆上尽量多两两相交的区间. 所以我们先按左端点极角排序,然后固定一个必须 ...
- Is the Information Reliable?(差分约束系统)
http://poj.org/problem?id=2983 题意:给出M条信息,判断这些信息的正确性.(1)V A B :表示A,B之间的距离>=1; (2)P A B X :表示A B之间的 ...
- shopnc学习
---恢复内容开始--- 以前没有怎么接触过shopnc,感觉界面挺漂亮的,不过后来自己需要开发一个电商系统,就顺便参考了下,感觉构架垃圾的一塌糊涂.不过平时做这个系统二次开发的业务比较多,所以简单的 ...
- codevs1557 热浪(堆优化dijkstra)
1557 热浪 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 德克萨斯纯朴的民眾们这个夏 ...
- Akka源码分析-ask模式
在我之前的博文中,已经介绍过要慎用Actor的ask.这里我们要分析一下ask的源码,看看它究竟是怎么实现的. 开发时,如果要使用ask方法,必须要引入akka.pattern._,这样才能使用ask ...
- 基于Spark Streaming预测股票走势的例子(一)
最近学习Spark Streaming,不知道是不是我搜索的姿势不对,总找不到具体的.完整的例子,一怒之下就决定自己写一个出来.下面以预测股票走势为例,总结了用Spark Streaming开发的具体 ...
- ACM_三角形蛇形矩阵
三角形蛇形矩阵 Time Limit: 2000/1000ms (Java/Others) Problem Description: 小铠觉得各类题型是要温故而知新的,所以他叫小发出一道类似做过的题. ...
- asp.net mvc 最简单身份验证 [Authorize]通过的标准
[Authorize] public ContentResult Index2() { return Content("验证通过了"); } 经常能够看到某个Controler下的 ...
- java_基础知识_字符串练习题_计算两个字符串的最长公共字串长度
package tek; Java算法——求出两个字符串的最长公共字符串 /** * @Title: 问题:有两个字符串str1和str2,求出两个字符串中最长公共字符串. * @author 匹夫( ...
- hibernate 级联删除报更新失败的问题(org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update)
首先hibernate级联删除的前提是,首先需要在映射文件中配置,配置多表之间的关联关系: 下面以部门表(Dept)和员工表(Emp)为例: 1.在Emp.hbm.xml映射文件中配置many-to- ...