题目链接:ZOJ 2482 IP Address
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn = 10010;
const int INF = 0x3f3f3f3f;
int a[maxn];
int main()
{
int n;
scanf("%d",&n);
string s;
while(n--)
{
cin>>s;
reverse(s.begin(), s.end());
int len = s.length();
int cnt = 0,tmp = 0;
for(int i=0;i<len;i++)
{
tmp += (s[i]-'0')*pow(2,i%8);
if(i%8==7)
{
a[++cnt] = tmp;
tmp = 0;
}
}
printf("%d.%d.%d.%d\n",a[4],a[3],a[2],a[1]);
}
return 0;
}