zoukankan      html  css  js  c++  java
  • 【Codeforces 1B】Spreadsheets

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

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

    【题解】

    转换方法说实话特别恶心>_< 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());
    		}
    	}
    }
    
  • 相关阅读:
    HTTP POST GET 本质区别详解
    本人完成的代码生成器,请多提些建议
    .net实现控件视图状态ViewState
    专门用于微信公众平台的Javascript API导言
    [学习笔记]验证上传文件后缀名类型
    专门用于微信公众平台的Javascript API
    1个月成为HTML5前端工程师
    js中用正则表达式 过滤特殊字符, 校验所有输入域是否含有特殊符号
    SharePoint 2010 根据不同的用户权限显示不同的导航
    (原创)Sharepoint webpart中调用web service报错
  • 原文地址:https://www.cnblogs.com/AWCXV/p/10363519.html
Copyright © 2011-2022 走看看