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 ...
随机推荐
- images have the “stationarity” property, which implies that features that are useful in one region are also likely to be useful for other regions.
Convolutional networks may include local or global pooling layers[clarification needed], which combi ...
- [转】IIS:Do not nest virtual directories
原文:https://msdn.microsoft.com/en-us/library/ms178685.aspx#Anchor_6 Configuration settings for virtua ...
- 项目中nodejs包高效升级插件npm-check-updates
nodejs包高效升级插件npm-check-updates 最近想升级npm的包 1.//常规的包升级方式/2.npm update (包) 到npm一搜发现了一个很好的升级工具 npm-check ...
- Linux ~ termios 串口编程
ermios 结构是在POSIX规范中定义的标准接口,它类似于系统V中的termio接口,通过设置termios类型的数据结构中的值和使用一小 组函数调用,你就可以对终端接口进行控制. 可以被调整来影 ...
- 模仿jquery框架源码
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...
- php正则表达式和数组
一.正则表达式 1. “/”代表定界符,"^"代表起始符号,"$"代表结束符号 $str1="abc123def45ghjk6789lou" ...
- jQuery图片水平滑动延迟加载动画
在线演示 本地下载
- poj 1019 Number Sequence 【组合数学+数字x的位宽函数】
题目地址:http://poj.org/problem?id=1019 Number Sequence Time Limit: 1000MS Memory Limit: 10000K Total ...
- LINQ 学习路程 -- 查询操作 Aggregate
聚合操作执行数学的运算,如平均数.合计.总数.最大值.最小值 Method Description Aggregate 在集合上执行自定义聚集操作 Average 求平均数 Count 求集合的总数 ...
- a note of R software write Function
Functionals “To become significantly more reliable, code must become more transparent. In particular ...