Skip to content

Instantly share code, notes, and snippets.

@haggen
Last active November 19, 2015 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haggen/bfb69fba4ec4ad3bb6f7 to your computer and use it in GitHub Desktop.
Save haggen/bfb69fba4ec4ad3bb6f7 to your computer and use it in GitHub Desktop.
codingames.com
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
int main()
{
int n; // the number of temperatures to analyse
scanf("%d", &n); fgetc(stdin);
char temps[257]; // the n temperatures expressed as integers ranging from -273 to 5526
fgets(temps,256,stdin); // the n temperatures expressed as integers ranging from -273 to 5526
// Write an action using printf(). DON'T FORGET THE TRAILING \n
// To debug: fprintf(stderr, "Debug messages...\n");
fprintf(stderr, "%d\n%s\n", n, temps);
if(n == 0)
{
printf("0\n");
return 0;
}
int hn = -273; //highest negative temperature
int lp = 5526; //lowest positive temperature
char *str = strtok(temps, " ");
while(str != NULL)
{
int temp;
sscanf(str, "%d", &temp);
fprintf(stderr, "%d\n", temp);
str = strtok(NULL, " ");
if(temp > 0)
{
if(temp < lp)
{
lp = temp;
}
}
else
{
if(temp > hn)
{
hn = temp;
}
}
}
int r = lp + hn;
if(r > 0)
{
printf("%d\n", hn);
}
else
{
printf("%d\n", lp);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment