码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Beta Round #1 B. Spreadsheets

时间:2014-06-05 00:14:09      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:codeforces   刷题   

Codeblocks坏掉了,我不知道该怎么修,只能过两天重装系统了。

没办法。这个题是用Java写的,代码风格不好不要骂我~~


题目大意:

Excel表格那种坐标系统,和正常的坐标系统。用代码实现转换。


就是模拟题啊,代码量比较小。


下面是代码:

import java.util.Scanner;
public class Main {
	public static void main(String[] args)  {
		Scanner cin = new Scanner(System.in);
		int t = cin.nextInt(),temp;
		while(t-->0)
		{
			String s = cin.next();
			int div=26;
			if(s.charAt(0)=='R'&&s.charAt(1)>='0'&&s.charAt(1)<='9')
			{
				int i;
				for(i=0;i<s.length();i++)
				{
					if(s.charAt(i)=='C')break;
				}
				if(i==s.length())
				{
					for(i=0;i<s.length();i++)
					{
						if(s.charAt(i)>='0'&&s.charAt(i)<='9')break;
					}
					int b=1;
					temp=0;
					for(int j=i-1;j>=0;j--)
					{
						temp+=(s.charAt(j)-'A'+1)*b;
						b*=26;
					}
					String num=s.substring(i,s.length());
					System.out.println("R"+num+"C"+temp);
					continue;
				}
				String num=s.substring(i+1,s.length());
				temp=Integer.valueOf(num);
				int flat=0;
				num="";
				while(temp>0)
				{
					if(temp%div==0)
					{
						num+="Z";
						temp-=div;
					}
					else 
					{
						int x=temp%div;
						x/=(div/26);
						x--;
						char c =(char) x;
						c+='A';
						num+=String.valueOf(c);
						temp-=temp%div;
					}
					div*=26;
				}
				for(int j=num.length()-1;j>=0;j--)
				{
					System.out.print(num.charAt(j));
				}
				num=s.substring(1,i);
				System.out.println(num);
			}
			else 
			{
				int i;
				for(i=0;i<s.length();i++)
				{
					if(s.charAt(i)>='0'&&s.charAt(i)<='9')break;
				}
				int b=1;
				temp=0;
				for(int j=i-1;j>=0;j--)
				{
					temp+=(s.charAt(j)-'A'+1)*b;
					b*=26;
				}
				String num=s.substring(i,s.length());
				System.out.println("R"+num+"C"+temp);
			}
		}
		cin.close();
	}
}


Codeforces Beta Round #1 B. Spreadsheets,布布扣,bubuko.com

Codeforces Beta Round #1 B. Spreadsheets

标签:codeforces   刷题   

原文地址:http://blog.csdn.net/lin375691011/article/details/27093709

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!