POJ 2105 IP Address(简单模拟)
2016-05-02 15:08
316 查看
题目地址:http://poj.org/problem?id=2105
思路:模拟
AC代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
const int inf = 0x3f3f3f3f;//1061109567
typedef long long LL;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
char a[40];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",a+1);
int sum = 0;
for(int i=1; i<=8; i++)
{
int x = 8 - i;
sum +=(a[i] - '0')* pow(2,x);
}
printf("%d.",sum);
sum = 0;
for(int i=9; i<=16; i++)
{
int x = 16 - i;
sum +=(a[i] - '0')* pow(2,x);
}
printf("%d.",sum);
sum = 0;
for(int i=17; i<=24; i++)
{
int x = 24 - i;
sum +=(a[i] - '0')* pow(2,x);
}
printf("%d.",sum);
sum = 0;
for(int i=25; i<=32; i++)
{
int x = 32 - i;
sum +=(a[i] - '0')* pow(2,x);
}
printf("%d\n",sum);
}
return 0;
}
思路:模拟
AC代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
const int inf = 0x3f3f3f3f;//1061109567
typedef long long LL;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
char a[40];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",a+1);
int sum = 0;
for(int i=1; i<=8; i++)
{
int x = 8 - i;
sum +=(a[i] - '0')* pow(2,x);
}
printf("%d.",sum);
sum = 0;
for(int i=9; i<=16; i++)
{
int x = 16 - i;
sum +=(a[i] - '0')* pow(2,x);
}
printf("%d.",sum);
sum = 0;
for(int i=17; i<=24; i++)
{
int x = 24 - i;
sum +=(a[i] - '0')* pow(2,x);
}
printf("%d.",sum);
sum = 0;
for(int i=25; i<=32; i++)
{
int x = 32 - i;
sum +=(a[i] - '0')* pow(2,x);
}
printf("%d\n",sum);
}
return 0;
}
相关文章推荐
- 数据可视化的实现技术和工具比较(HTML5 canvas(Echart)、SVG、webGL等等)
- 2、内核基本学习
- 洛谷P1803凌乱的yyy
- Emacs快速指南摘要
- 【平衡树】splay
- Haar特征的另一种的快速计算方法—boxfilter
- 数据结构之排序:直接插入排序
- 深入学习PHP内核
- iOS CMTimeMake 和 CMTimeMakeWithSeconds 学习
- UITableView基本使用(二)
- 226. Invert Binary Tree
- Ubuntu下挂载Windows分区
- MBR引导系统启动的几个概念
- 针对MATLAB(imfilter)翻译C语言(opencv)遇到的问题
- MataLab-GUI编程初探
- 委托简单的用法
- matlab .m文件的编写&使用
- 委托简单的用法
- Linux学习笔记:常用100条命令(三)
- Objective-C学习笔记