<file_sep>// CodinGame - Entrainement 1

#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n1;
    int n2;
    string line;
    string w1;
    string w2;

    cin >> n1 >> n2;
    cin.ignore(); // this reads the '\n' just after n2

    getline(cin, line);

    cin >> w1 >> w2;

    // logic comes here...
    if (n1 + n2 == (int)line.size()) {
        cout << w1 << endl;
    } else {
        cout << w2 << endl;
    }

    return 0;
}
<file_sep># codingame

Mes réalisations en C++ sur CodinGame

## Mes participations:
 - 29/01/2013
 - 26/03/2013
 
## Description des branchs
 - **master**  : Branche contenant les projets vides de chaque énoncé
 - **stable**  : Branche dérivée de *master*, contenant les sources compilant un programme passant 100% des tests
 - **testing** : Branche dérivée de *master*, contenant des sources à l'état de travail

## Description d'un répertoire
Chaque exercice est stocké dans son arborescence propre:
 - enonce.txt     : Contient l'énoncé de l'exercice
 - CMakeLists.txt : Permet de générer un nouveau projet avec cmake
 - test/          : Répertoire contenant les fichiers de tests
 - src/           : Répertoire contenant les fichiers sources

La procédure de test "test.sh" est externe et se trouve à la racine du dépôt.
<file_sep>cmake_minimum_required(VERSION 2.6)

#Configuration du projet
project("20121222-1-Sms_Vokia")

set(EXECUTABLE_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE})
ENABLE_TESTING()

#Génération de la liste des fichiers sources
file(
    GLOB_RECURSE
    source_files
    src/*
)

#Déclaration de l'exécutable
add_executable(
    20121222-1
    ${source_files}
)

#Déclaration des tests
add_test(
    NAME Test_1
    COMMAND ${PROJECT_BINARY_DIR}/../test.sh ${PROJECT_BINARY_DIR}/${EXECUTABLE_OUTPUT_PATH}/20121222-1 ${PROJECT_BINARY_DIR}/test/ 1
)
add_test(
    NAME Test_2
    COMMAND ${PROJECT_BINARY_DIR}/../test.sh ${PROJECT_BINARY_DIR}/${EXECUTABLE_OUTPUT_PATH}/20121222-1 ${PROJECT_BINARY_DIR}/test/ 2
)
add_test(
    NAME Test_3
    COMMAND ${PROJECT_BINARY_DIR}/../test.sh ${PROJECT_BINARY_DIR}/${EXECUTABLE_OUTPUT_PATH}/20121222-1 ${PROJECT_BINARY_DIR}/test/ 3
)
add_test(
    NAME Test_4
    COMMAND ${PROJECT_BINARY_DIR}/../test.sh ${PROJECT_BINARY_DIR}/${EXECUTABLE_OUTPUT_PATH}/20121222-1 ${PROJECT_BINARY_DIR}/test/ 4
)
add_test(
    NAME Test_5
    COMMAND ${PROJECT_BINARY_DIR}/../test.sh ${PROJECT_BINARY_DIR}/${EXECUTABLE_OUTPUT_PATH}/20121222-1 ${PROJECT_BINARY_DIR}/test/ 5
)
add_test(
    NAME Test_6
    COMMAND ${PROJECT_BINARY_DIR}/../test.sh ${PROJECT_BINARY_DIR}/${EXECUTABLE_OUTPUT_PATH}/20121222-1 ${PROJECT_BINARY_DIR}/test/ 6
)
add_test(
    NAME Test_7
    COMMAND ${PROJECT_BINARY_DIR}/../test.sh ${PROJECT_BINARY_DIR}/${EXECUTABLE_OUTPUT_PATH}/20121222-1 ${PROJECT_BINARY_DIR}/test/ 7
)
add_test(
    NAME Test_8
    COMMAND ${PROJECT_BINARY_DIR}/../test.sh ${PROJECT_BINARY_DIR}/${EXECUTABLE_OUTPUT_PATH}/20121222-1 ${PROJECT_BINARY_DIR}/test/ 8
)
add_test(
    NAME Test_9
    COMMAND ${PROJECT_BINARY_DIR}/../test.sh ${PROJECT_BINARY_DIR}/${EXECUTABLE_OUTPUT_PATH}/20121222-1 ${PROJECT_BINARY_DIR}/test/ 9
)

<file_sep>#!/bin/bash
# $1 = binary to test
# $2 = tests dir
# $3 = test number

binary="$1"
test_dir="$2"
test_number="$3"
test_in="${test_dir}/in${test_number}.txt"
test_out="${test_dir}/out${test_number}.txt"
test_result="out_$$.txt"
time_result="time_$$.txt"

time_limit="1.00"

if [ ! -f "${binary}" ]
then
    echo "Seems the binary '${binary}' doesn't exist."
    exit 1
fi
if [ ! -x "${binary}" ]
then
    echo "Seems the binary '${binary}' is not executable."
    exit 1
fi
if [ ! -d "${test_dir}" ]
then
    echo "Seems the directory '${test_dir}' doesn't exist."
    exit 1
fi
if [ -z "${test_number}" ]
then
    echo "Seems the test number was not given."
    exit 1
fi
if [ ! -f "${test_in}" ]
then
    echo "Seems the test '${test_number}' doesn't have an input file."
    exit 1
fi
if [ ! -f "${test_out}" ]
then
    echo "Seems the '${test_number}' doesn't have an output file."
    exit 1
fi


/usr/bin/time -f %e -o "${time_result}" "${binary}" < "${test_in}" | tee "${test_result}"
diff -B --suppress-common-lines "${test_result}" "${test_out}"
ok=$?
if [ "${ok}" = "0" ]
then
    echo "${time_limit}" >> "${time_result}"
    if [ "`sort "${time_result}" | head -n1`" = "${time_limit}" ]
    then
        echo "
****************** REUSSITE PARTIELLE DU TEST (DEPASSEMENT DU TEMPS)"
    else
        echo "
****************** REUSSITE DU TEST"
    fi
else
    echo "
****************** ECHEC DU TEST"
fi

rm -f "${test_result}" "${time_result}"
exit ${ok}

<file_sep>// CodinGame - Entrainement 2

#include <iostream>
#include <string>
#include <stdlib.h>

#define MAX_TEMPERATURE 5526
#define MIN_TEMPERATURE -273
#define MAX_INPUT 10000
#define MIN_INPUT 0
using namespace std;

int main()
{
    int n=0;                        // The number of temperature
    int tmin=MAX_TEMPERATURE;       // The temperature closest of zero
    int tminplus=MAX_TEMPERATURE;   // The temperature closest of zero (absolute value)
    int t=0;                        // The current temperature
    int m=0;                        // The number of input read


    cin >> n;       // Read n
    if ((n < MIN_INPUT) || (n >MAX_INPUT)){
        cerr << "ERROR: The number of temperature must be between " << MIN_INPUT << " and " << MAX_INPUT << endl;
        return 1;
    }
    cin.ignore();   // this reads the '\n' just after n2

    // Read all the input
    for(int i=0; i<n; i++){
        cin >> t;
        if ((t < MIN_TEMPERATURE) || (t >MAX_TEMPERATURE)){
            cerr << "WARNING: The temperature " << t << " is off range ([" << MIN_INPUT << " ; " << MAX_INPUT << "])" << endl;
        } else {
            if(abs(t)<=tminplus){
                if ((t==tminplus) && (tmin<0))
                {
                    tminplus=t;
                    tmin=t;
                } else
                {
                    if (t<tminplus) {
                        tminplus=abs(t);
                        tmin=t;
                    }
                }
            }
            m++;
        }
    }

    if (m == 0) {
        // No temperature in input
        cout << 0 << endl;
    } else {
        if (m < n) {
            cerr << "WARNING: " << n << " input expected. Received only " << m << endl;
        }
        cout << tmin << endl;
    }

    return 0;
}
<file_sep>// Read inputs from stdin. Write outputs to stdout.

#include <iostream>
#include <string>

using namespace std;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {	
		cout << "Hello World!" << endl;
	}
	
	return 0;
}
<file_sep>cmake_minimum_required(VERSION 2.6)

#Configuration du projet
project("20121025-1-L'art_ASCII")

set(EXECUTABLE_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE})
ENABLE_TESTING()

#Génération de la liste des fichiers sources
file(
    GLOB_RECURSE
    source_files
    src/*
)

#Déclaration de l'exécutable
add_executable(
    20121025-1
    ${source_files}
)

#Déclaration des tests
add_test(
    NAME Test_1
    COMMAND ${PROJECT_BINARY_DIR}/../test.sh ${TARGET} ${PROJECT_BINARY_DIR}/test/ 1
)
add_test(
    NAME Test_2
    COMMAND ${PROJECT_BINARY_DIR}/../test.sh ${PROJECT_BINARY_DIR}/${EXECUTABLE_OUTPUT_PATH}/20121025-1 ${PROJECT_BINARY_DIR}/test/ 2
)
add_test(
    NAME Test_3
    COMMAND ${PROJECT_BINARY_DIR}/../test.sh ${PROJECT_BINARY_DIR}/${EXECUTABLE_OUTPUT_PATH}/20121025-1 ${PROJECT_BINARY_DIR}/test/ 3
)
add_test(
    NAME Test_4
    COMMAND ${PROJECT_BINARY_DIR}/../test.sh ${PROJECT_BINARY_DIR}/${EXECUTABLE_OUTPUT_PATH}/20121025-1 ${PROJECT_BINARY_DIR}/test/ 4
)
add_test(
    NAME Test_5
    COMMAND ${PROJECT_BINARY_DIR}/../test.sh ${PROJECT_BINARY_DIR}/${EXECUTABLE_OUTPUT_PATH}/20121025-1 ${PROJECT_BINARY_DIR}/test/ 5
)

