【链接】 我是链接,点我呀:)

【题意】

A~Z分别对应了1~26
AA是27依次类推
让你完成双向的转换

【题解】

转换方法说实话特别恶心>_

【代码】

  1. import java.io.*;
  2. import java.util.*;
  3. public class Main {
  4. static InputReader in;
  5. static PrintWriter out;
  6. public static void main(String[] args) throws IOException{
  7. //InputStream ins = new FileInputStream("E:\\rush.txt");
  8. InputStream ins = System.in;
  9. in = new InputReader(ins);
  10. out = new PrintWriter(System.out);
  11. //code start from here
  12. new Task().solve(in, out);
  13. out.close();
  14. }
  15. static int N = (int)1e6;
  16. static class Task{
  17. boolean isdigit(char key) {
  18. if (key>='0' && key<='9') return true;
  19. else return false;
  20. }
  21. int strtoint(String s) {
  22. int temp = 1;
  23. int cur = 0;
  24. int len = s.length();
  25. for (int i = len-1;i >= 0;i--) {
  26. cur = cur + temp*(s.charAt(i)-'A'+1);
  27. temp = temp*26;
  28. }
  29. return cur;
  30. }
  31. String inttostr(int col) {
  32. StringBuilder sb = new StringBuilder();
  33. int cur = 26;
  34. int cnt = 1;
  35. while (col>cur) {
  36. col-=cur;
  37. cur = cur*26;
  38. cnt++;
  39. }
  40. for (int i = 1;i <= cnt;i++) {
  41. for (int j = 26;j>=1;j--)
  42. if ((j-1)*(cur/26)<col) {
  43. col-=(j-1)*cur/26;
  44. char key = (char)(j+'A'-1);
  45. sb = sb.append(key);
  46. cur/=26;
  47. break;
  48. }
  49. }
  50. return sb.toString();
  51. }
  52. public void solve(InputReader in,PrintWriter out) {
  53. int n;
  54. n = in.nextInt();
  55. int []num = new int[2];
  56. for (int i = 1;i <= n;i++) {
  57. String s = in.next();
  58. int cnt = 0;
  59. int len = s.length();
  60. int fir = 0;
  61. for (int j = 0;j < len;j++) {
  62. if (isdigit(s.charAt(j))) {
  63. int k = j;
  64. fir = j;
  65. while (k+1<len && isdigit(s.charAt(k+1)) ) k++;
  66. //j..k全是数字
  67. int temp = 0;
  68. for (int l = j;l <= k;l++)
  69. temp = temp*10+s.charAt(l)-'0';
  70. num[cnt++] = temp;
  71. j = k;
  72. }
  73. }
  74. if (cnt==1) {
  75. //AB12
  76. int rows = num[0];
  77. int col = strtoint(s.substring(0, fir));
  78. out.println("R"+rows+"C"+col);
  79. }else {
  80. int rows = num[0];int cols = num[1];
  81. String strcols = inttostr(cols);
  82. out.println(strcols+rows);
  83. }
  84. }
  85. }
  86. }
  87. static class InputReader{
  88. public BufferedReader br;
  89. public StringTokenizer tokenizer;
  90. public InputReader(InputStream ins) {
  91. br = new BufferedReader(new InputStreamReader(ins));
  92. tokenizer = null;
  93. }
  94. public String next(){
  95. while (tokenizer==null || !tokenizer.hasMoreTokens()) {
  96. try {
  97. tokenizer = new StringTokenizer(br.readLine());
  98. }catch(IOException e) {
  99. throw new RuntimeException(e);
  100. }
  101. }
  102. return tokenizer.nextToken();
  103. }
  104. public int nextInt() {
  105. return Integer.parseInt(next());
  106. }
  107. }
  108. }

【Codeforces 1B】Spreadsheets的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  3. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  4. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  5. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  6. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  7. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  8. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

  9. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

随机推荐

  1. bzoj3663

    几何+lis 很巧妙.直接做很困难,那么我们转化一下,把每个点能看见的圆弧画出来.只有这些圆弧相交时才满足条件. 那么也就是找出圆上尽量多两两相交的区间. 所以我们先按左端点极角排序,然后固定一个必须 ...

  2. 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之间的 ...

  3. shopnc学习

    ---恢复内容开始--- 以前没有怎么接触过shopnc,感觉界面挺漂亮的,不过后来自己需要开发一个电商系统,就顺便参考了下,感觉构架垃圾的一塌糊涂.不过平时做这个系统二次开发的业务比较多,所以简单的 ...

  4. codevs1557 热浪(堆优化dijkstra)

    1557 热浪  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description 德克萨斯纯朴的民眾们这个夏 ...

  5. Akka源码分析-ask模式

    在我之前的博文中,已经介绍过要慎用Actor的ask.这里我们要分析一下ask的源码,看看它究竟是怎么实现的. 开发时,如果要使用ask方法,必须要引入akka.pattern._,这样才能使用ask ...

  6. 基于Spark Streaming预测股票走势的例子(一)

    最近学习Spark Streaming,不知道是不是我搜索的姿势不对,总找不到具体的.完整的例子,一怒之下就决定自己写一个出来.下面以预测股票走势为例,总结了用Spark Streaming开发的具体 ...

  7. ACM_三角形蛇形矩阵

    三角形蛇形矩阵 Time Limit: 2000/1000ms (Java/Others) Problem Description: 小铠觉得各类题型是要温故而知新的,所以他叫小发出一道类似做过的题. ...

  8. asp.net mvc 最简单身份验证 [Authorize]通过的标准

    [Authorize] public ContentResult Index2() { return Content("验证通过了"); } 经常能够看到某个Controler下的 ...

  9. java_基础知识_字符串练习题_计算两个字符串的最长公共字串长度

    package tek; Java算法——求出两个字符串的最长公共字符串 /** * @Title: 问题:有两个字符串str1和str2,求出两个字符串中最长公共字符串. * @author 匹夫( ...

  10. hibernate 级联删除报更新失败的问题(org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update)

    首先hibernate级联删除的前提是,首先需要在映射文件中配置,配置多表之间的关联关系: 下面以部门表(Dept)和员工表(Emp)为例: 1.在Emp.hbm.xml映射文件中配置many-to- ...