HDOJ(HDU) 2106 decimal system(进制相互转换问题)
Problem Description
As we know , we always use the decimal system in our common life, even using the computer. If we want to calculate the value that 3 plus 9, we just import 3 and 9.after calculation of computer, we will get the result of 12.
But after learning <>,we know that the computer will do the calculation as the following steps:
1 computer change the 3 into binary formality like 11;
2 computer change the 9 into binary formality like 1001;
3 computer plus the two number and get the result 1100;
4 computer change the result into decimal formality like 12;
5 computer export the result;
In the computer system there are other formalities to deal with the number such as hexadecimal. Now I will give several number with a kind of change method, for example, if I give you 1011(2), it means 1011 is a number in the binary system, and 123(10) means 123 if a number in the decimal system. Now I will give you some numbers with any kind of system, you guys should tell me the sum of the number in the decimal system.
Input
There will be several cases. The first line of each case contains one integers N, and N means there will be N numbers to import, then there will be N numbers at the next N lines, each line contains a number with such form : X1….Xn.(Y), and 0<=Xi
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
long sum=0;
int n =sc.nextInt();
String str = null;
for(int i=0;i<n;i++){
str =sc.next();
String strs[] = str.split("\\(");
int num = Integer.parseInt( strs[0]);
String strHex = "";
for(int j=0;j<strs[1].length();j++){
if(strs[1].charAt(j)!=')'){
strHex = strHex+strs[1].charAt(j);
}
}
int hex = Integer.parseInt(strHex);
if(hex==10){
sum+=num;
}else{
//hex为num这个数的进制基数。也就是说num为hex进制的数。
//返回的是一个十进制的数。。
num = Integer.parseInt(Integer.toString(num), hex);
sum+=num;
}
}
System.out.println(sum);
}
}
}
HDOJ(HDU) 2106 decimal system(进制相互转换问题)的更多相关文章
- HDU 2106 decimal system (进制转化求和)
题意:给你n个r进制数,让你求和. 析:思路就是先转化成十进制,再加和. 代码如下: #include <iostream> #include <cstdio> #includ ...
- HDOJ(HDU) 2097 Sky数(进制)
Problem Description Sky从小喜欢奇特的东西,而且天生对数字特别敏感,一次偶然的机会,他发现了一个有趣的四位数2992,这个数,它的十进制数表示,其四位数字之和为2+9+9+2=2 ...
- HDOJ(HDU) 2502 月之数(进制)
Problem Description 当寒月还在读大一的时候,他在一本武林秘籍中(据后来考证,估计是计算机基础,狂汗-ing),发现了神奇的二进制数. 如果一个正整数m表示成二进制,它的位数为n(不 ...
- hdu 2106 decimal system
#include <cstdio> #include <cstring> #include <algorithm> #include <cmath> # ...
- php实现文件与16进制相互转换
php实现文件与16进制相互转换 <pre><?php/** * php 文件与16进制相互转换 * Date: 2017-01-14 * Author: fdipzone * Ve ...
- Python语言中各种进制相互转换
目录 Python语言中各种进制相互转换 将二进制.八进制.十进制的数分别转换成十进制的方法 将十进制转换成二进制.八进制.十六进制 Python语言中各种进制相互转换 本文参考自https://ww ...
- java中 8进制 10进制 2进制 16进制 相互转换
十进制转成十六进制: Integer.toHexString(int i) 十进制转成八进制 Integer.toOctalString(int i) 十进制转成二进制 Integer.toBinar ...
- HDU 3001 Travelling 3进制状压dp
题意:10个点,若干条边,边有花费,每个点最多走两次,求走过所有点,花费最少 分析:因为每个点最多走两次,所以联想到3进制,然后枚举状态,就行了(我也是照着网上大神的代码写的) #include &l ...
- sql 进制转换,支持93内的进制相互转换
功能:实现在SQL内进制的互相转换,支持从2 - 93进制内的转换,若需要支持其他字符,可以自定义@ym变量实现扩充 -- ====================================== ...
随机推荐
- (转)function($){}(window.jQuery) 是什么意思?
function(){}(); (function(){})(); 这两个是self-invoking anonymous 自调匿名函数,用这类的方法,能强制使匿名函数成为表达式,把不合法变成合法. ...
- 国内流行的两大开源.net微信公众平台SDK对比分析
最近忙于微信周边的开发 难免手痒去搜索一下有没有相关的sdk直接拿来使 还真发现了不少 这里总结两个看起来比较不错的.net平台下基于C#语言开发的SDK 一个强大一个小巧 (1) Senparc.W ...
- Canvas模糊化处理图片、毛玻璃处理图片之stackblur.js
Canvas实现毛玻璃效果解决方式1:使用stackblur.js 在Android系统中实现图片的毛玻璃效果比较好用的类库是:Android StackBlur 官方Git地址:https://gi ...
- java Web Services搭建环境时遇到的各种问题,记录一下。 java.lang.OutOfMemoryError: PermGen space,org/apache/struts2/util/ObjectFactoryDestroyable
情况:在同一个,myEclipes 下加载俩个项目,一个seriver端,一个client端. 必备: myEclipes ,apache-tomcat-7.0.42,apache-tomcat ...
- 那些常用的eclipse快捷键
用了很久的eclipse了,有些快捷键常用,有的偶尔使用,现在记下常用的快捷键,以便大家和自己查用(持续更新) 这些快捷键都可以在[window]-[preferences]-[general]-[k ...
- animationWithKeyPath键值对
animationWithKeyPath键值对的方式来改变动画 <Jacky Shin:可以从这个网址查到哪些可以做为动画效果, 打开xcode帮助,搜索animatable propertie ...
- OC - 28.模拟时钟
效果图 实现思路 该示例通过隐式动画实现 表盘通过显示在imageView中的一张图片来实现 在表盘上绘制(时分秒)三条直线,分别位于不同的图层,且时针位于最下层,秒针位于最上层 设置直线为圆角 直线 ...
- 移动触摸事件(touchstart、touchmove和touchend)
touchstart事件:当手指触摸屏幕时候触发,即使已经有一个手指放在屏幕上也会触发. touchmove事件:当手指在屏幕上滑动的时候连续地触发.在这个事件发生期间,调用preventDefaul ...
- oracle常见为题汇总,以及一个简单数据连接操作工厂
本人软件环境:win8.1 64位操作系统,vs2013,安装好了与oracle数据库对应的客户端 连接oracle数据库.以及操作数据库 1.使用IIS建立网站,浏览网页时候,提示“ ...
- Execl DataTime Format Number
Excel 中日期类型所保存的值是数值型.只是设置了为日期格式,通过公式转换从而得出我们平时常用的日期内容.也很好理解这公式所要说明的意思.数值是个浮点型可以分成2部分看.整数部分:年月日(日期)小数 ...