Written by
daweibayu
on
on
Poj 2105
#include <iostream>
#include <string>
using namespace std;
char numToChar(int num)
{
return num + '0';
}
int baseStrToInt(const string& sequence, int base)
{
int result = 0;
for(int i = 0; i < sequence.length(); i++)
{
result = result*base + sequence[i] - '0';
}
return result;
}
string intToBaseStr(int num, int base)
{
string result;
while(num)
{
result = numToChar(num % base) + result;
num /= base;
}
if(result.empty())
result = "0";
return result;
}
int main()
{
int n;
string sequence;
cin >> n;
while(n--)
{
cin >> sequence;
string result = "";
result += intToBaseStr(baseStrToInt(sequence.substr(0, 8), 2), 10) + ".";
result += intToBaseStr(baseStrToInt(sequence.substr(8, 8), 2), 10) + ".";
result += intToBaseStr(baseStrToInt(sequence.substr(16, 8), 2), 10) + ".";
result += intToBaseStr(baseStrToInt(sequence.substr(24, 8), 2), 10);
cout << result << endl;
}
}