working on it ...

Filters

Explore Public Snippets

Sort by

Found 1 snippet

    public by FelipeTRM  17224  188  7  0

    Codingame - Temperatures - C++

    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    
    /**
     * Auto-generated code below aims at helping you parse
     * the standard input according to the problem statement.
     **/
    int main()
    {
        int N,c; // the number of temperatures to analyse
        scanf("%d", &N);
        int number[N],ptemps,i=0,FLAG=0,mark;
    
        for(i=0;i<N;i++){
            scanf("%d",&number[i]);
           }
    
        sort(number,number+N);
    
        for(i=0;i<N;i++){
           if(number[i]>0)FLAG++;
           if(FLAG==1)mark=i;
        }
    
        if(N==0)printf("0");
        else if(-1*number[mark-1]<number[mark])printf("%d",number[mark-1]);
        else printf("%d",number[mark]);
    
    }

    List Complete ( 1 snippet total )

    Cannot find what you were looking for?
    Ask the Snip2Code Community

    • Public Snippets
    • Channels Snippets