poj 2105 IP Address(水题)
一、Description
is form by grouping 8 bits at a time and converting the binary representation to decimal representation. Any 8 bits is a valid part of an IP address. To convert binary numbers to decimal numbers remember that both are positional numerical systems, where the
first 8 positions of the binary systems are:
27 26 25 24 23 22 21 20 128 64 32 16 8 4 2 1
Input
Output
二、题解
今天见鬼了,碰到这么多水题。这题就是在采用什么读取输入流时纠结了一下,最后还是用了SC,然后再用字符串的性质解决了问题。
三、java代码
import java.util.Scanner;
public class Main {
public static int transform(String s){
int sum=0;
if(s.charAt(0)=='1')
sum+=128;
if(s.charAt(1)=='1')
sum+=64;
if(s.charAt(2)=='1')
sum+=32;
if(s.charAt(3)=='1')
sum+=16;
if(s.charAt(4)=='1')
sum+=8;
if(s.charAt(5)=='1')
sum+=4;
if(s.charAt(6)=='1')
sum+=2;
if(s.charAt(7)=='1')
sum+=1;
return sum;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n,i;
String s;
n=sc.nextInt();
for(i=0;i<n;i++){
s=sc.next();
System.out.println(transform(s.substring(0,8))+"."+transform(s.substring(8,16))+"."
+transform(s.substring(16,24))+"."+transform(s.substring(24,32)));
}
}
}
poj 2105 IP Address(水题)的更多相关文章
- OpenJudge/Poj 2105 IP Address
1.链接地址: http://poj.org/problem?id=2105 http://bailian.openjudge.cn/practice/2105 2.题目: IP Address Ti ...
- poj 2105 IP Address
IP Address Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 18951 Accepted: 10939 Desc ...
- POJ 1488 Tex Quotes --- 水题
POJ 1488 题目大意:给定一篇文章,将它的左引号转成 ``(1的左边),右引号转成 ''(两个 ' ) 解题思路:水题,设置一个bool变量标记是左引号还是右引号即可 /* POJ 1488 T ...
- POJ 3641 Oulipo KMP 水题
http://poj.org/problem?id=3461 直接KMP就好.水题 #include<cstdio> #include<cstring> const int M ...
- poj 1006:Biorhythms(水题,经典题,中国剩余定理)
Biorhythms Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 110991 Accepted: 34541 Des ...
- poj 1002:487-3279(水题,提高题 / hash)
487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 236746 Accepted: 41288 Descr ...
- poj 1003:Hangover(水题,数学模拟)
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 99450 Accepted: 48213 Descri ...
- poj 2000 Gold Coins(水题)
一.Description The king pays his loyal knight in gold coins. On the first day of his service, the kni ...
- POJ 3673 Cow Multiplication (水题)
题意:给你两个数,求所有的数位的积的和. 析:太水了,没的说,可以先输入边算,也可以最后再算,一样.. 代码如下: #include <cstdio> #include <strin ...
随机推荐
- What is the difference between iterations and epochs in Convolution neural networks?
https://stats.stackexchange.com/questions/164876/tradeoff-batch-size-vs-number-of-iterations-to-trai ...
- lua调试小技巧
lua中,如果碰到某个属性值改变了,但是修改的地方又特别多,调试就特别麻烦了,有个小技巧,直接贴代码 local m = { __index = function( t, k ) ...
- windows7下cmd命令窗口没有滚动条的解救方法
由于昨天的好123问题没有解决,我想查看一下本机的ip地址等,于是打开了cmd窗口,输入ipconfig/all命令进行查看,但是发现出现了下面的窗口,无法进行滚动,完全无法查看详细的信息. 然后我百 ...
- inux c编程:记录锁
记录锁的功能:当一个进程正在读或修改文件的某个部分是,它可以阻止其他进程修改同一文件区.对于这个功能阐述我认为有三点要解释的: 记录锁不仅仅可以用来同步不同进程对同一文件的操作,还可以通过对同一文件加 ...
- 使用apt-get 安装后的mysql 登录问题
当使用apt-get安装mysql后,ubuntu会自动生成一个用户名和密码.所以在第一次登陆时会报如下错误 ERROR 1045 (28000): Access denied for user 'd ...
- php类和对象(一)
对象:任何东西都可以称为对象,类实例化出来的东西类:对所有同类的对象抽象出来的东西 Info: Code,Name,Sex,Nation,Birthday对象:一条具体的信息 p001 张三 男 汉族 ...
- [原创]Scala学习:Tuple,Array,Map ,文件操作
1.Tuple:元祖.是一个有用的容器对象. 1)特点: ① 元祖是不可变的,即,当声明完了一个元祖,那么它的长度就不可以在改变: ② 元祖可以包含不同类型的数据,对象: ③ 索引是从 '_1 ...
- poj 3126 Prime Path 【bfs】
题目地址:http://poj.org/problem?id=3126 Input One line with a positive number: the number of test cases ...
- 要成为一个 Java 架构师得学习哪些知识?
作者:zhuqz链接:https://www.zhihu.com/question/29031276/answer/54631312来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请 ...
- bzoj 2005: [Noi2010]能量采集 筛法||欧拉||莫比乌斯
2005: [Noi2010]能量采集 Time Limit: 10 Sec Memory Limit: 552 MB[Submit][Status][Discuss] Description 栋栋 ...