working on it ...

Filters

Explore Public Snippets

Sort by

Found 5 snippets matching: codingames

    public by FelipeTRM  17219  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]);
    
    }

    external by skarthikeyan96  12  0  1  0

    codingames problem #1

    codingames problem #1: script.js
    /*   
    i/p : 4
    o/p : 1234
          +123
          ++12
          +++1  
    */ 
    
    var a  = [1,2,3,4];
    console.log(a.join(""))
    for(var i=0;i<a.length-1;i++)
    {
    a.unshift("+")
    a.pop()
    console.log(a.join(""))
    }
    
    

    external by aka7h  22  0  1  0

    Easy 3 in codingames.com

    Easy 3 in codingames.com: The_Descent.py
    import sys, math
    
    # Auto-generated code below aims at helping you parse
    # the standard input according to the problem statement.
    
    
    # game loop
    while 1:
        l=[]
        SX, SY = [int(i) for i in input().split()]
        for i in range(8):
            MH = int(input()) # represents the height of one mountain, from 9 to 0. Mountain heights are provided from left to right.
            l.append(MH)
            m = max(l)
            C = l.index(m)
        if SX == C:
            print('FIRE')
        else:
            print('HOLD')
    
    

    external by Arthur Corenzan  130  0  2  0

    codingames.com

    codingames.com: temperatures.c
    #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;
    }
    
    
    

    external by jonatak  161  0  2  0

    First version, need to be improved

    First version, need to be improved: CodinGameSkyNetTheVirus.scala
    import math._
    import scala.util._
    
    object Player extends App {
        // n: the total number of nodes in the level, including the gateways
        // l: the number of links
        // e: the number of exit gateways
        val Array(n, l, e) = for(i <- readLine split " ") yield i.toInt
        
        var path = (for(i <- 0 until l) yield {
            var Array(a, b) = readLine split " "
            (a.toInt, b.toInt)
        }).toSet
    
        val wayout = for(i <- 0 until e) yield readInt
        
        while(true) {
            val si = readInt
            val col1 = path.par.filter { 
                case (a, b) => si == a || si == b
            }
            
            val col2 = col1.par.filter { 
                case (a: Int, b: Int) => wayout.contains(a) || wayout.contains(b)
            }
            
            if (col2.size > 0) {
                val (x, y) = col2.head
                println(s"$x $y")
                path = path - Tuple2(x, y)
            } else {
                val (x, y) = col1.head
                println(s"$x $y")
                path = path - Tuple2(x, y)
            }
        }
    }
    
    

    List Complete ( 5 snippets total )

    • Public Snippets
    • Channels Snippets