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 ...
随机推荐
- 1.设计模式-------Iterator
本文主要是参考<图解设计模式>写的读书笔记: 开发中我用到遍历集合时候,无非我常用的就是简单的for循环,foreach,iterator 这三种方式进行遍历! 当然这三种的效率: 学习I ...
- 洛谷 P3629 [APIO2010]巡逻
题目在这里 这是一个紫题,当然很难. 我们往简单的想,不建立新的道路时,从1号节点出发,把整棵树上的每条边遍历至少一次,再回到1号节点,会恰好经过每条边两次,路线总长度为$2(n-1)$,根据树的深度 ...
- centos install docker setup centos7 安装docker
centos7 安装docker 1: 安装必要的一些系统工具sudo yum install -y yum-utils device-mapper-persistent-data lvm2 2: 添 ...
- R语言数据管理(五)
一.数据的输入: 手动输入:edit( )函数 也可修改 mydata <- data.frame(age=numeric(0),gender=character(0),weight=numer ...
- Shell中的while循环
while循环的格式 while expression do command command ``` done 1.计数器控制的while循环 主要用于已经准确知道要输入的数据和字符串的数目 ...
- Video Brightness Enhancement
Tone Mapping原是摄影学中的一个术语,因为打印相片所能表现的亮度范围不足以表现现实世界中的亮度域,而如果简单的将真实世界的整个亮度域线性压缩到照片所能表现的亮度域内,则会在明暗两端同时丢失很 ...
- 本地储存(localStorage)记录
- 本地存储 + localStorage.getItem("search_history") 获取本地存储 + localStorage.setItem("a" ...
- 爬虫 spider
python 2.x # -*- coding: utf-8 -*-import reimport urllib url = 'http://tieba.baidu.com/p/4872795764' ...
- Map集合按照value和key进行排序
最近由于特殊的业务需求,需要做相关数据排序,下面就贴出其中的将map集合中按照value或者key进行排序的代码,后面再具体详说. /** * map 集合排序 * @param map * @ret ...
- 多种方法求java求整数的位数
方法一 private static int getNumLenght(long num){ num = num>0?num:-num; return String.valueOf(num).l ...