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 ...
随机推荐
- SVM vs. Softmax
http://cs231n.github.io/linear-classify/
- eclipse InvocationTargetException 错误解决
1.今天做一个推送的,用到了几个jar包,直接以User Library的形式加进 在单元测试中,测试的很好,没有任何问题, 但是在action中测试,一测试就崩. 跟踪以后出现InvocationT ...
- Django模型系统——ORM校园管理系统代码
1.models.py from django.db import models # Create your models here. class Class(models.Model): id = ...
- 《程序员代码面试指南》第三章 二叉树问题 判断t1 树中是否有与t2 树拓扑结构完全相同的子树
题目 判断t1 树中是否有与t2 树拓扑结构完全相同的子树 java代码 package com.lizhouwei.chapter3; /** * @Description: 判断t1 树中是否有与 ...
- 【leetcode刷题笔记】Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations ...
- Python3 内置函数补充匿名函数
Python3 匿名函数 定义一个函数与变量的定义非常相似,对于有名函数,必须通过变量名访问 def func(x,y,z=1): return x+y+z print(func(1,2,3)) 匿名 ...
- 【FLASK模板】set,with语句
# set with 语句 ###set语句:在模板中, 可以使用 ‘set’语句来定义变量, 实例如下: <body> {% set username='zhiliaoketang' % ...
- CSS3图片悬停放大动画
在线演示 本地下载
- 20165101刘天野 2018-2019-2《网络对抗技术》Exp7 网络欺诈防范
目录 20165101刘天野 2018-2019-2<网络对抗技术>Exp7 网络欺诈防范 1.实验内容 1.1 简单应用SET工具建立冒名网站 1.2 ettercap DNS spoo ...
- echo 命令参数
echo 命令参数: -n 不换行输出 -e 解析转义字符(\n \t \b \r)