题意:a = 1, b = 2, ..., z = 26, aa = 27, ...

给字符串或者数字,输出对应的答案。

解法:类似26进制……但又不完全是……拿java大数模拟了一下……

代码:

import java.util.*;
import java.math.*; public class Main
{
public static void main(String args[])
{
Scanner cin = new Scanner(System.in);
while(true)
{
String input = cin.next();
if(input.equals("*"))
break;
String ans1 = "", ans2 = "";
if(input.charAt(0) >= '0' && input.charAt(0) <= '9')
{
ans2 = input;
BigInteger x = new BigInteger(input);
while(!x.equals(BigInteger.ZERO))
{
if(x.equals(BigInteger.valueOf(26)))
{
ans1 += 'z';
break;
}
ans1 += (char)('a' + (Integer.parseInt(x.mod(BigInteger.valueOf(26)).toString()) + 25) % 26);
if(x.mod(BigInteger.valueOf(26)).equals(BigInteger.ZERO))
{
x = x.divide(BigInteger.valueOf(26));
x = x.add(BigInteger.valueOf(-1));
}
else
x = x.divide(BigInteger.valueOf(26));
}
}
else
{
ans1 = input;
BigInteger x = BigInteger.ZERO;
for(int i = 0; i < input.length(); i++)
{
x = x.multiply(BigInteger.valueOf(26));
x = x.add(BigInteger.valueOf((int)input.charAt(i) - 'a' + 1));
}
ans2 = x.toString();
}
if(input.charAt(0) >= '0' && input.charAt(0) <= '9')
for(int i = ans1.length() - 1; i >= 0; i--)
System.out.print(ans1.charAt(i));
else
System.out.print(ans1);
for(int i = 22 - ans1.length(); i > 0; i--)
System.out.print(" ");
int len = ans2.length() % 3;
int res = ans2.length();
for(int i = 0; i < len; i++)
System.out.print(ans2.charAt(i));
for(int i = len; i < res; i += 3)
{
if(i != 0)
System.out.print(',');
System.out.print(ans2.charAt(i));
System.out.print(ans2.charAt(i + 1));
System.out.print(ans2.charAt(i + 2));
}
System.out.println("");
}
}
}

  

POJ 1312 Numerically Speaking的更多相关文章

  1. HDU 1314 Numerically Speaking(大数加减乘除+另类二十六进制互相转换)

    原题代号:HDU 1314 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1314 Numerically Speaking Time Limit: 2 ...

  2. 【HDOJ】1314 Numerically Speaking

    学了几天的Java了,终于独立A了一道大数计算.感觉还得练Java啊. import java.util.Scanner; import java.math.BigInteger; import ja ...

  3. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  4. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  5. POJ 1595 Prime Cuts (ZOJ 1312) 素数打表

    ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=312 POJ:http://poj.org/problem?id=159 ...

  6. HDOJ 1312 (POJ 1979) Red and Black

    Problem Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...

  7. poj 题目分类(1)

    poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...

  8. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

  9. 转载:poj题目分类(侵删)

    转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码)  ...

随机推荐

  1. oracle 表空间 用户

    Oracle创建表空间.创建用户以及授权.查看权限 创建临时表空间 CREATE TEMPORARY TABLESPACE test_temp TEMPFILE 'C:\oracle\product\ ...

  2. 【leetcode】Combination Sum (middle)

    Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...

  3. POJ 1906

    #include <iostream> #include <string> #define MAXN 150 using namespace std; int _m[MAXN] ...

  4. java基础知识回顾之java Thread类--java线程实现常见的两种方式实现Runnable接口(二)

    创建线程的第二中方式: /** *      步骤: 1定义类实现Runnable接口      2.实现Runnable接口中的run方法.      3.通过Thread类建立线程对象,并将Run ...

  5. CSS中nth-child和nth-of-type的简单使用

    ele:nth-child是查找父元素下的子元素,包括子元素类型非ele的,当子元素类型不是ele时,则不会进行任何操作: ele:nth-of-type是查找父元素下的子元素类型为ele的元素,其是 ...

  6. *[topcoder]TheMatrix

    http://community.topcoder.com/stat?c=problem_statement&pm=13035 矩阵棋盘的题,比较典型.可以定两条column夹住,然后上下扫, ...

  7. Rebound-Android的弹簧动画库

    Rebound是facebook出品的一个弹簧动画库,与之对应的IOS版本有一个pop动画库,也是非常的强大给力.Facebook真是互联网企业中的楷模,开源了很多的实用开源库,大赞一个!!! 讲解R ...

  8. iOS 开发--github的demo

    令人惊讶的是,YYText 虽然代码量很大(超过一万行),但它只是 ibireme 的作品之一.ibireme 利用业余时间完成了 YYKit 工具库,包括: YYModel — 高性能的 iOS J ...

  9. Yii2 的问题解决方案

    yii2 Class 'app\controllers\AccessControl' not found 一般是命名空间问题, 写成\yii\filters\AccessControl::classN ...

  10. Java API —— 网络编程

    1.网络编程概述     1)网络编程概述     · 计算机网络         是指将地理位置不同的具有独立功能的多台计算机及其外部设备,通过通信线路连接起来,在网络操作系统,网络管理软件及网络通 ...