• poj1312


    java中StringBuffer类似于C++中的String,append函数可以在其后面添加字符,reverse可以反转。

    java中BigInteger的intValue方法可以将其转为int。

    View Code
    import java.io.*;
    import java.util.*;
    import java.math.*;
    
    
    public class Main {
        final static int maxl = 50;
        static String translate(String temp)
        {
            StringBuffer ret = new StringBuffer(temp);
            for (int i = ret.length() - 3; i > 0; i -= 3)
                ret.insert(i, ",");
            return ret.toString();
        }
        static void translateToNumber(String st)
        {
            BigInteger ret = new BigInteger("0");
            for (int i = 0; i < st.length(); i++)
            {
                ret = ret.multiply(BigInteger.valueOf(26));
                ret = ret.add(BigInteger.valueOf(st.charAt(i) - 'a' + 1));
    //            System.out.println(ret);
            }
            System.out.printf("%-22s%s\n", st, translate(ret.toString()));
        }
        
        static void translateToString(String st)
        {
            BigInteger a = new BigInteger(st);
            StringBuffer ans = new StringBuffer("");
            while (!a.equals(BigInteger.ZERO))
            {
                BigInteger temp = a.mod(BigInteger.valueOf(26));
                if (temp.equals(BigInteger.ZERO))
                {
                    ans.append("z");
                    a = a.subtract(BigInteger.valueOf(26));
                }else
                    ans.append((char) (temp.intValue() + 'a' - 1));
                a = a.divide(BigInteger.valueOf(26));
    //            System.out.println(a);
            }
            ans.reverse();
            System.out.printf("%-22s%s\n", ans, translate(st));
        }
        
        public static void main(String[] args) throws FileNotFoundException
        {
    //        Scanner cin = new Scanner(new FileInputStream("t.txt"));
            Scanner cin = new Scanner(System.in);
            while (true)
            {
                String st = cin.next();
                if (st.equals("*"))
                    break;
                if (st.charAt(0) <= 'z' && st.charAt(0) >= 'a')
                    translateToNumber(st);
                else
                    translateToString(st);
            }
        }
    }
  • 相关阅读:
    [Beta]Scrum Meeting#1
    Alpha阶段事后分析
    Alpha阶段项目展示
    Alpha阶段测试报告
    Beta阶段测试报告
    【Beta阶段】第九次Scrum Meeting
    压力测试报告
    [技术博客]几种网站压力测试工具调研与使用
    【Beta阶段】第八次Scrum Meeting
    【Beta阶段】第七次Scrum Meeting
  • 原文地址:https://www.cnblogs.com/rainydays/p/2866282.html
Copyright © 2020-2023  润新知