>>105906209um. acshually the size of the input is not constant. String compare is O(n) which will always make longer input strings take longer
here you go. I le optimized it to actually O(1)
int is_hacker(char* _ip, int n) {
char ip[16];
memset(ip, ' ', sizeof(ip));
strncpy(ip, _ip, n);
if (strcmp(ip, "1.1.1.1 ", 15) == 0) {
return 0; // not a hacker
} if (strcmp(ip, "1.1.1.2 ", 15) == 0) {
return 0; // not a hacker
} if (strcmp(ip, "1.1.1.3 ", 15) == 0) {
return 0; // not a hacker
} if (strcmp(ip, "1.1.1.4 ", 15) == 0) {
return 0; // not a hacker
} if (strcmp(ip, "1.1.1.5 ", 15) == 0) {
return 0; // not a hacker
} if (strcmp(ip, "1.1.1.6 ", 15) == 0) {
return 0; // not a hacker
} if (strcmp(ip, "1.1.1.7 ", 15) == 0) {
return 0; // not a hacker
} ...
}
but actually 15 byte string IPs will take the longest if you count like this so maybe it's still O(n) technically. I think you'd have to shuffle all the IPs randomly for it to not be O(n). funnily enough doing it in reverse will generate the first ever O(1/n) that I've ever encountered