Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴个AC代码吧。。

Posted by yzhw at 2011-08-25 02:12:24 on Problem 1312
import java.io.*;
import java.math.*;
public class Main {

	static BigInteger num[]=new BigInteger[21],std[]=new BigInteger[26],mul=new BigInteger("26");
	static void print(String str,String num)
	{
		System.out.printf("%-22s",str);
		for(int i=0;i<num.length();i++)
		{
			if((num.length()-i)%3==0&&i!=0) System.out.print(',');
			System.out.print(num.charAt(i));
		}
		System.out.println();
	}
	static String tonum(String str)
	{
		BigInteger ans=BigInteger.ONE;
		for(int i=1;i<str.length();i++)
			ans=ans.add(num[i]);
		for(int i=0;i<str.length();i++)
			ans=ans.add(num[i].multiply(std[str.charAt(str.length()-1-i)-'a']));
		return ans.toString();
	}
	static String tostr(String str)
	{
		BigInteger tmp=new BigInteger(str);
		tmp=tmp.add(BigInteger.ONE.negate());
		int len=1;
		for(len=1;len<=20;len++)
			if(tmp.compareTo(num[len])>0)
				tmp=tmp.add(num[len].negate());
			else break;
		char ans[]=new char[len];
		for(int i=len-1;i>=0;i--)
		{
			ans[len-1-i]=(char)('a'+tmp.divide(num[i]).intValue());
			tmp=tmp.mod(num[i]);
		}
		return new String(ans);
	}
	public static void main(String[] args) throws IOException {
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		String str;
		num[0]=BigInteger.ONE;
		std[0]=BigInteger.ZERO;
		for(int i=1;i<26;i++)
			std[i]=std[i-1].add(BigInteger.ONE);
		for(int i=1;i<=20;i++)
			num[i]=num[i-1].multiply(mul);
		while(true)
		{
			str=in.readLine();
			if(str.equals("*")) break;
			else if(str.charAt(0)<='9')//digit
				print(tostr(str),str);
			else//alphabetic
			    print(str,tonum(str));
		}
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator