|
@@ -0,0 +1,66 @@
|
|
|
|
+#include <cstdio>
|
|
|
|
+#include <cstdlib>
|
|
|
|
+
|
|
|
|
+const int M = 1000;
|
|
|
|
+
|
|
|
|
+char buf[16];
|
|
|
|
+
|
|
|
|
+int mask[] = {1 << 7, 1 << 6, 1 << 5, 1 << 4, 1 << 3, 1 << 2, 1 << 1, 1};
|
|
|
|
+
|
|
|
|
+void itob(int i, bool *b) {
|
|
|
|
+ for (int j = 0; j < 8; j++) {
|
|
|
|
+ b[j] = i & mask[j];
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int btoi(bool *b) {
|
|
|
|
+ int i = 0;
|
|
|
|
+ for (int j = 0; j < 8; j++) {
|
|
|
|
+ if (b[j]) i += mask[j];
|
|
|
|
+ }
|
|
|
|
+ return i;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool ip[M][32];
|
|
|
|
+
|
|
|
|
+void print_ip(int m) {
|
|
|
|
+ for (int i = 0; i < m; i++) {
|
|
|
|
+ for (int j = 0; j < 32; j++) {
|
|
|
|
+ printf("%d", ip[i][j]);
|
|
|
|
+ }
|
|
|
|
+ printf("\n");
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int main() {
|
|
|
|
+ int m;
|
|
|
|
+ scanf("%d\n", &m);
|
|
|
|
+ for (int i = 0; i < m; i++) {
|
|
|
|
+ scanf("%s\n", buf);
|
|
|
|
+ for (int pre = 0, cur = 0, j = 0; j < 4; j++) {
|
|
|
|
+ while (buf[cur] != '.' && buf[cur] != 0) cur++;
|
|
|
|
+ buf[cur] = 0;
|
|
|
|
+ int num = atoi(buf + pre);
|
|
|
|
+ itob(num, ip[i] + 8 * j);
|
|
|
|
+ cur++;
|
|
|
|
+ pre = cur;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ int i;
|
|
|
|
+ for (i = 0; i < 32; i++) {
|
|
|
|
+ bool flag = ip[0][i];
|
|
|
|
+ for (int j = 0; j < m; j++) {
|
|
|
|
+ if (ip[j][i] != flag) goto end;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+end:
|
|
|
|
+ for (int j = i; j < 32; j++) {
|
|
|
|
+ ip[0][j] = false;
|
|
|
|
+ }
|
|
|
|
+ printf("%d.%d.%d.%d\n", btoi(ip[0]), btoi(ip[0] + 8), btoi(ip[0] + 16), btoi(ip[0] + 24));
|
|
|
|
+ for (int j = 0; j < i; j++) {
|
|
|
|
+ ip[0][j] = true;
|
|
|
|
+ }
|
|
|
|
+ printf("%d.%d.%d.%d\n", btoi(ip[0]), btoi(ip[0] + 8), btoi(ip[0] + 16), btoi(ip[0] + 24));
|
|
|
|
+ return 0;
|
|
|
|
+}
|