**
航电oj:IP Address
**
#题目描述

#给你n个字符串 转换为n个IP地址
#一个一个的处理 8个一分
#知识点
灵活运用
#代码
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int data[9]={0,128,64,32,16,8,4,2,1};//便于计算
int ans[5];
char s;
int t,temp,tempsum;
int main()
{
scanf("%d",&t);
while(t--)
{
int flag = 0;
tempsum =0;
for(int i=1;i<=4;i++)
{
tempsum = 0;//八个一份 要制零
for(int j=1;j<=8;j++)
{
cin >> s;//这个用scanf 好像不行 不太懂
int ss = s - '0';//!!!这里是字符转成数字
if(ss)
{
temp = data[j];
tempsum += temp;
}
}
ans[i] = tempsum ;
}
printf("%d.%d.%d.%d\n",ans[1],ans[2],ans[3],ans[4]);
}
return 0;
}
#总结
要细心的弄 不要弄错了 真的搞心态!!!
本文介绍了一个将输入的字符串转换为IP地址的C++程序实现。通过逐位读取字符并根据IP地址的二进制表示进行计算,最终输出转换后的IP地址。文章详细解释了程序的运行逻辑及注意事项。
896

被折叠的 条评论
为什么被折叠?



