Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.1 kB
1
Indexable
Never
uint32_t findNonPairGuest(std::vector<uint32_t> &invitationalCodeVector) {
    std::sort(invitationalCodeVector.begin(), invitationalCodeVector.end());
    for(auto it = invitationalCodeVector.begin(); it != invitationalCodeVector.end();) {
        auto nextIt = std::next(it);
        if(*it != *nextIt || nextIt == invitationalCodeVector.end()) {
            return *it;
        }
        std::advance(it, 2);
    }
    return 0;
}

int main()
{
    using std::cin;
    using std::cout;

    uint16_t cases;
    cin >> cases;
    int caseNumber = 1;
    while(cases > 0) {
        std::vector<uint32_t> invitationalCodeVector {};
        uint16_t guestsCount;
        cin >> guestsCount;
        uint32_t invitationalCode;
        uint32_t nonPairedGuest = 0;
        while(guestsCount > 0) {
            cin >> invitationalCode;
            invitationalCodeVector.push_back(invitationalCode);
            guestsCount--;
        }
        nonPairedGuest = findNonPairGuest(invitationalCodeVector);
        cout << "Case #" << caseNumber << ": " << nonPairedGuest << std::endl;
        caseNumber++;
        cases--;
    }
    return 0;
}