最后一点真的不想改了 , 烦,不过这次真的学到了很多东西
代码如下
#include<cstdio>
#include<cstdlib>
#include<cstring>
int n;
int main() {
while (scanf_s("%d", &n)) {
int x[4], mid;
char all[32], string[32], string2[8];
memset(string, '0', sizeof(string));
memset(string2, '0', sizeof(string2));
memset(all, '0', sizeof(all));
for (int time = 0; time < n; time++) {
scanf_s("%d.%d.%d.%d", &x[1], &x[2], &x[3], &x[4]);
//解码、封装
for (int i = 0; i < 4; i++) {
_itoa_s(x[i], string2, 1, 2);
int len = strlen(string2);
if (len < 8)
for (int j = 0; j < len; j++) {
mid = string2[len];
string2[8 - len] = string2[len];
string2[len] = mid;
}
strcat_s(string, string2);
memset(string2, 0, sizeof(string2));
}
for (int i = 0; i < 32; i++) {
if (all[i] = string[i])
all[i]++;
}
}
int k;
char *num;
_itoa_s(n, num, 1,10);
for (k = 31; k >= 0; k--) {
if (all[k] != '0'&& all[k] == *num) {
break;
}
}
int m=31;
while (m-- > k)
all[m] = '0';
printf("%s", all);
while (m-- >= 0)
all[m] = '1';
printf("%s", all);
return 0;
}
}