POJ - 1017

#include 

int GetPacketNum(int s1, int s2, int s3, int s4, int s5, int s6) {
    int PacketNum = 0;
    int s1_c = 0;
    int s2_c = 0;
    int s3_c = 0;

    PacketNum += s6;
    //printf("1Num is %d\n", PacketNum);
    PacketNum += s5;
    //printf("2Num is %d\n", PacketNum);
    s1_c += 11 * s5;
    PacketNum += s4;
    //printf("3Num is %d\n", PacketNum);
    s2_c += 5 * s4;
    PacketNum += (s3 + 3) / 4;
    //printf("4Num is %d\n", PacketNum);
    s3_c += ((s3 + 3) / 4) * 4 - s3;

    switch (s3_c) {
        case 3: {
            s2_c += 5;
            s1_c += 7;
            break;
        }
        case 2: {
            s2_c += 3;
            s1_c += 6;
            break;
        }
        case 1: {
            s2_c += 1;
            s1_c += 5;
            break;
        }
        case 0: {break; }
        default: printf("Error! s3_c value must inside {0,1,2,3}...");
    }

    if (s2 >
        s2_c) {
        s2 = s2 - s2_c;
        PacketNum += (s2 + 8)/9;
        //printf("5Num is %d\n", PacketNum);
        s2_c = ((s2 + 8) / 9) * 9 - s2;
    }
    else {
        s2_c = s2_c - s2;
    }

    s1_c += 4 * s2_c;
    if (s1 >= s1_c) {
        PacketNum += ((s1 - s1_c) + 35) / 36;
        //printf("6Num is %d\n", PacketNum);
    }

    return PacketNum;
}

int main() {
    int s1, s2, s3, s4, s5, s6;
    while (scanf("%d%d%d%d%d%d", &s1, &s2, &s3, &s4, &s5, &s6) \
        && s1 + s2 + s3 + s4 + s5 + s6) {
        printf("%d\n", GetPacketNum(s1, s2, s3, s4, s5, s6));
    }
}

你可能感兴趣的:(POJ - 1017)