poj2105 IP Address(简单题)
题目链接: id=2105">http://poj.org/problem?id=2105
----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋:http://user.qzone.qq.com/593830943/main
----------------------------------------------------------------------------------------------------------------------------------------------------------
Description
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
Sample Input
4
00000000000000000000000000000000
00000011100000001111111111111111
11001011100001001110010110000000
01010000000100000000000000000001
Sample Output
0.0.0.0
3.128.255.255
203.132.229.128
80.16.0.1
题意:非常easy, 就是每一个案例给出一个32位的2进制数字串。 要求依照每8位转换为8进制输出(中间有‘.’)就可以!
代码例如以下:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int N;
int i, j;
char s[117];
while(cin >> N)
{
while(N--)
{
cin>>s;
int ans[4], k = 7, l = 0;
int sum = 0;
for(i = 0; i < 32; i++)
{
sum +=(s[i]-'0')*pow(2.0,k);
k--;
if(i%8==7)
{
ans[l++] = sum;
sum = 0;
k = 7;
}
}
cout<<ans[0]<<'.'<<ans[1]<<'.'<<ans[2]<<'.'<<ans[3]<<endl;
}
}
return 0;
}
poj2105 IP Address(简单题)的更多相关文章
- poj 2105 IP Address(水题)
一.Description Suppose you are reading byte streams from any device, representing IP addresses. Your ...
- [LeetCode] 1108. Defanging an IP Address
Description Given a valid (IPv4) IP address, return a defanged version of that IP address. A defange ...
- [LintCode] Restore IP Address 复原IP地址
Given a string containing only digits, restore it by returning all possible valid IP address combina ...
- 华东师大OJ:IP Address【IP地址转换】
/*===================================== IP Address Time Limit:1000MS Memory Limit:30000KB Total Subm ...
- UVa 1590 IP网络(简单位运算)
Description Alex is administrator of IP networks. His clients have a bunch of individual IP addres ...
- [LeetCode] Restore IP Address [28]
题目 Given a string containing only digits, restore it by returning all possible valid IP address comb ...
- LeetCode 1108. Defanging an IP Address (IP 地址无效化)
题目标签:String 题目给了我们一组 ip address,让我们把 . 变成 [.],这题可以用replace,但是这样做的话,好像没意义了.所以还是走一下array,具体看code. Java ...
- hectf2020部分简单题题解wp
HECTF 我真是又菜又没时间肝题..又又又只水了波简单题... Reverse 1.Hello_Re file查一波 32bit,拖进IDA中 老规矩shift+F12 查看字符串: 跳转 F5查看 ...
- 【LeetCode】468. Validate IP Address 解题报告(Python)
[LeetCode]468. Validate IP Address 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: h ...
随机推荐
- Android:真机调试,不显示logcat的解决方案
有时做开发的时候,用真机测试,总是看不到logcat信息 .原因是系统默认关闭了log,需要将其打开. 解决办法如下: 在拨号界面输入*#*#2846579#*#* ,然后系统会自动弹出一个菜单, ...
- 使用ffmpeg实现转码样例(代码实现)
分类: C/C++ 使用ffmpeg实现转码样例(代码实现) 使用ffmpeg转码主要工作如下: Demux -> Decoding -> Encoding -> Muxing 其中 ...
- mvc项目,导出到Excel,中文显示乱码
1 public class HomeController : Controller 2 { 3 static List<User> GetUsers() 4 { 5 List< ...
- POJ 1401 Factorial
题意:求一个数的阶乘最后边有几个0. 解法:如果有0说明这个数含有2和5这两个因子,对于一个阶乘来说因子2的数量一定比5的数量多,所以只要算有几个5就可以了,依次算5的个数,25的个数,125的个数… ...
- JAX-RPC
JAX-RPC(基于可扩展标记语言XML的远程过程调用的Java应用程序接口)是Java Web服务开发包(WSDP)的应用程序接口(API),WSDP能使Java开发者在Web服务或其他的Web应用 ...
- C语言内存地址基础
来源:http://blog.jobbole.com/44845/ 从计算机内存的角度思考C语言中的一切东东,是挺有帮助的.我们可以把计算机内存想象成一个字节数组,内存中每一个地址表示 1 字节.比方 ...
- IOS UIActivityIndicatorView 等待指示器
自己做的一个 等待指示器 #import <UIKit/UIKit.h> @interface RockIndicatorView : UIView { } @property(nonat ...
- SQL经典笔试题之一
本题用到下面三个关系表: CARD 借书卡. CNO 卡号,NAME 姓名,CLASS 班级 BOOKS 图书. BNO 书号,BNAME 书名,AUTHOR 作者,PRIC ...
- Objective-C异步编程
1. 不要阻塞主线程 不管在进行iOS还是OS X开发中,主线程都只应该处理用户交互和界面布局,好的程序通常能够随时快速响应用户的操作,所以CPU密集型或者会阻塞线程的代码应该在其他位置去执行,我指的 ...
- MVC & MVVM
什么是MVC,什么是MVVM? 面向过程 --> 面向对象 --> MVC --> MV* 面向过程: 开发人员按照需求逻辑顺序开发代码逻辑,主要思维模式在于如何实现.先细节,后整体 ...
