Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

幫我看看吧,換了3個算法仍是WA

Posted by miklcct at 2012-09-14 23:58:46 on Problem 2799
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator