Problem: On standard stream of input we get sequence of sets of numbers from diapason [0, 31]. Every set finished by -1. Every set may be empty and numbers may be repeated in set. You need to find XOR of all sets and output a hexadecimal representation of result, i.e we obtain {1, 2, 3}, {3, 4}, {1, 5} and result is {2, 4, 5}, thus a hexadecimal representation is 34. Each number in the result set corresponds to bit in the 32-bit hexadecimal representation.
#include <stdio.h>
#include <inttypes.h>
#include <stdint.h>
int main() {
int32_t currentNum;
uint32_t num = 0, result = 0;
while (scanf("%"SCNd32, ¤tNum) == 1) {
if (currentNum != -1) {
num |= 1 << currentNum;
} else {
result ^= num;
num = 0;
}
}
printf("%x\n", result);
return 0;
}
This problem is simple and my solution is above. But I have following problem : the testing system in which I send a code return me a run-time error. I can't imagine where is mistake and I can't come up with a such test that return run-time error. Could you give me any tips?