Created
April 4, 2014 18:22
-
-
Save OlivierLi/9980332 to your computer and use it in GitHub Desktop.
hackerrank default file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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