/*Copyright ElohimTov LLC*/ /* //Name:ElohimTovSolveCode - ConditionalStatements - C Solution //Problem: HackerRank - 30 Days of Code - ConditionalStatements //Current File: ElohimTovSolve_CondStatements.(c).txt //Compile-able File: ElohimTovSolve_CondStatements.c //Date: 06/08/2020 //Tale: ElohimTov Solve's Solution to HackerRank.com's //Conditional Statements problem, in C programming language. //Problem link at https://elohimtov.com/elohimtov.info. */ #include #include #include #include #include #include #include #include #include //declaration of global variables char* readline(); int zero = 0; int one = 1; int two = 2; int five = 5; int six = 6; int twenty = 20; int main() { char* N_endptr; char* N_str = readline(); int N = strtol(N_str, &N_endptr, 10); if (N_endptr == N_str || *N_endptr != '\0') { exit(EXIT_FAILURE); } if((N%two)==one) { printf("Weird\n"); } else { if(two<=N && N<=five) { printf("Not Weird\n"); } else if(six<=N && N<=twenty) { printf("Weird\n"); } else { printf("Not Weird\n"); }//ends inner if...else }//ends outer if...else return 0; }//ends int main() char* readline() { size_t alloc_length = 1024; size_t data_length = zero; char* data = malloc(alloc_length); while (true) { char* cursor = data + data_length; char* line = fgets(cursor, alloc_length - data_length, stdin); if (!line) { break; } data_length += strlen(cursor); if (data_length < alloc_length - one || data[data_length - one] == '\n') { break; } size_t new_length = alloc_length << one; data = realloc(data, new_length); if (!data) { break; } alloc_length = new_length; }//ends while loop if (data[data_length - one] == '\n') { data[data_length - one] = '\0'; }//ends if statement data = realloc(data, data_length); return data; }//ends char* readline() /*Copyright ElohimTov LLC*/