POJ 2105 IP Address

来源:互联网 发布:ubuntu安装postgresql 编辑:程序博客网 时间:2024/05/16 17:13

大水题。分四段,二进制转十进制即可。

#include <iostream>#include <cstdio>#include <cstring>using namespace std;char a[32];int main(){int t;scanf("%d", &t);while (t--){scanf("%s", a);for (int i = 0; i < 4; i++){int ans = 0, weight = 1;for (int j = (i + 1) * 8 - 1; j >= i * 8; j--){ans += weight * (a[j] - '0');weight *= 2;}printf("%d", ans);if (i != 3)printf(".");}printf("\n");}}


0 0