POJ 1312 Numerically Speaking
题意: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的更多相关文章
- HDU 1314 Numerically Speaking(大数加减乘除+另类二十六进制互相转换)
原题代号:HDU 1314 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1314 Numerically Speaking Time Limit: 2 ...
- 【HDOJ】1314 Numerically Speaking
学了几天的Java了,终于独立A了一道大数计算.感觉还得练Java啊. import java.util.Scanner; import java.math.BigInteger; import ja ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- POJ 1595 Prime Cuts (ZOJ 1312) 素数打表
ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=312 POJ:http://poj.org/problem?id=159 ...
- HDOJ 1312 (POJ 1979) Red and Black
Problem Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...
- poj 题目分类(1)
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...
- POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)
本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...
- 转载:poj题目分类(侵删)
转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码) ...
随机推荐
- MVC中SelectList和@Html.DropDownList("MainDuty_UserId","请选择")的运用
Models.Project model = projectdb.dbSet.SingleOrDefault(e => e.Project_ID == id); ViewB ...
- gulp下livereload和webserver实现本地服务器下文件自动刷新
一.前言 node从v0.10.26升级(为了匹配autoprefixer)到v5.3.0后出现了gulp插件兼容问题,在nodejs下各种新的插件出现问题,需要重新配置.livereload实现ch ...
- POJ 3286 How many 0's?
题目链接 题意 :写下m到n之间所有的数,会写多少个0. 思路 :先算0到m的,再算0到n的,最后相减. 网上有位大神是这么推的,看下面.... 首先转化成求 [0, x] 中所有数中,含有的 0 的 ...
- 在UWSGI和NGINX配合的情况下,配置个别目录上传及超时
笨办法就是多加一个LOCATION. 然后,自定义以下类似参数 client_max_body_size uwsgi_connect_timeout uwsgi_read_timeout server ...
- 用 Xamarin for VS 创建 aar 文件的绑定
预备工作:相关aar文件,Xamarin for VS一份.我这里以Android中挺火的 MaterialDesignLibrary 为例. 1.首先,创建一个Xamarin Binding Lib ...
- Exception in thread "AWT-EventQueue-0" java.lang.IllegalThreadStateException
在线程中出现这种错误的原因是多次启动start() 解决方法: 将start()改成 run()
- Python中Lambda, filter, reduce and map 的区别
Lambda, filter, reduce and map Lambda Operator Some like it, others hate it and many are afraid of t ...
- STL函数模板(即算法)一览
查找算法 adjacent_find:找出一个串中第一个不符合次序的地方 find,find_if:找出第一个符合条件的元素 find_first_of:在一个串中寻找第一个与另一个串中任意一个元素相 ...
- spring是怎样面向接口编程的?
1.只要分层,就涉及到接口来连接.各层之间只通过接口来向外暴露功能. 2.spring中service层调用dao层时候,service层声明接口变量,具体接口实现可以ioc注入
- Oracle配置详解
[Oracle连接字符串][Oracle Net Manager 服务命名配置][PL/SQL 登陆数据库] 连接数据库的几个重要参数: 1. 登陆用户名:user: 2. 登录密码:password ...