#define _CRT_SECURE_NO_WARNINGS #include #include typedef unsigned char byte; typedef unsigned int dword; const dword NUM_CELLS = 1 << 20, LAST_CELL = NUM_CELLS - 1; byte arr[NUM_CELLS]; byte ascii[256]; void init_ascii() { for (int i = '0'; i < '9'; i++) ascii[i] = i - '0'; for (int i = 'a'; i < 'f'; i++) ascii[i] = i - 'a' + 10; for (int i = 'A'; i < 'F'; i++) ascii[i] = i - 'A' + 10; } unsigned int calc_crc(const char *ip) { unsigned int crc = 0; for (int i = 0; i < 39; i++) { byte high = (crc >> 1) & 0xf; crc <<= 1; crc ^= high ^ ascii[ip[i]]; } return crc; } int main() { init_ascii(); FILE* fin = fopen("logstat.in", "rt"); int i = 0; do { char ip[256]; fscanf(fin, "%s", ip); if (strlen(ip) != 39) { printf("wrong count: %i", i); return 2; } if (ip[0] == 'x') break; unsigned int crc = calc_crc(ip); int shift = crc & 7; int index = crc >> 3; arr[index & LAST_CELL] |= (1 << shift); } while (i++ < 2000000); fclose(fin); if (i < 10000 || i > 2000000) { printf("wrong count: %i", i); //return 2; } int total = 0; for (i = 0; i < NUM_CELLS; i++) if (arr[i]) { for(byte j = 0, m = 1; j < 8; j++, m <<= 1) if(arr[i] & m) total++; } FILE *fout = fopen("logstat.out", "wt"); fprintf(fout, "%i", total); fclose(fout); return 0; }