Skip to content

Instantly share code, notes, and snippets.

@OlivierLi
Created April 4, 2014 18:22
Show Gist options
  • Save OlivierLi/9980332 to your computer and use it in GitHub Desktop.
Save OlivierLi/9980332 to your computer and use it in GitHub Desktop.
hackerrank default file
//Online version needs this define. But it gets defined twice on the local machine
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdio.h> /* printf, fgets */
#include <stdlib.h> /* atoi */
int main() {
#ifdef OFFLINE
FILE *fp=fopen("stdin.txt", "r");
#else
FILE *fp=stdin;
#endif
char *line = NULL;
size_t size;
//Read the first line to know the number of iterations
getline(&line, &size, fp);
int num_lines = atoi(line);
free(line);
//Loop over each iteration
for(int i=0; i<num_lines; ++i) {
getline(&line, &size, fp);
long int num_cuts = atol(line);
unsigned long long int max = (num_cuts/2)*(num_cuts-(num_cuts/2));
printf("%llu\n",max);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment