| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
幫我看看吧,換了3個算法仍是WA#include <cstdio>
using namespace std;
typedef unsigned Address;
Address read_ip_address() {
Address x;
unsigned char *p = reinterpret_cast<unsigned char *>(&x);
scanf("%hhu.%hhu.%hhu.%hhu", p + 3, p + 2, p + 1, p);
return x;
}
void write_ip_address(Address x) {
const unsigned char *p = reinterpret_cast<unsigned char *>(&x);
printf("%u.%u.%u.%u\n", p[3], p[2], p[1], *p);
}
int main() {
int m;
scanf("%d", &m);
Address network = read_ip_address(), mask = ~Address(0);
while (--m) {
Address machine = read_ip_address();
while ((machine & mask) != network) {
mask <<= 1;
network &= mask;
}
}
write_ip_address(network);
write_ip_address(mask);
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator