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的代码长度分类(主要参考最短代码和自己写的代码) ...
随机推荐
- CHM类型API文件打不开问题解决方法
这是CHM文档被锁定导致的问题,选择CHM文件,右键属性,解除锁定
- [wikioi]线段树练习
http://codevs.cn/problem/1080/ #include <vector> #include <iostream> #include <string ...
- ServletRequest中getReader()和getInputStream()只能调用一次的解决办法
转载:http://blog.sina.com.cn/s/blog_870cd7b90101fg58.html 最近使用spring mvc做项目,数据格式是json,有一个功能是实现记录请求的参数, ...
- LR_问题_无法使用LR的Controller,提示缺少license
问题描述 无法使用LR的Controller,提示缺少license 问题解决 使用开始->所有程序->HP LoadRunner->loadrunner,在打开界面的左上角选择co ...
- Orcle数据库编程:一
1.PL/SQL是一种块结构的语言,一个PL/SQL程序包含了一个或者多个逻辑块,逻辑块中可以声明变量,变量在使用之前必须先声明. declare mstu student%ROWTYPE;--定义参 ...
- JavaWeb项目开发案例精粹-第2章投票系统-005实体层
1. package com.sanqing.bean; /** * * 投票选项类 * */ public class VoteOption { private int voteOptionID; ...
- Yii2 基于RESTful架构的 advanced版API接口开发 配置、实现、测试
环境配置: 开启服务器伪静态 本处以apache为例,查看apache的conf目录下httpd.conf,找到下面的代码 LoadModule rewrite_module modules/mod_ ...
- NSDictionary 初始化
NSDictionary *dic1=[NSDictionary dictionaryWithObject:@"1" forKey:@"a"]; ...
- mac root用户初始密码设置
具体方法如下: 1)sudo su切换到root,输入的用户密码是当前用户的密码: 2)切换到root后,执行passwd root,设置root用户密码即可.
- Zookeeper核心机制
(如果感觉有帮助,请帮忙点推荐,添加关注,谢谢!你的支持是我不断更新文章的动力.本博客会逐步推出一系列的关于大型网站架构.分布式应用.设计模式.架构模式等方面的系列文章) Zookeeper是Hado ...