Last active
November 28, 2020 18:01
-
-
Save BruJu/09d6a53de332833eb1df1822fcdae90e to your computer and use it in GitHub Desktop.
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
// Trouver tous les noms qui finissent par 5 chiffres | |
/******* | |
* Read input from cin | |
* Use cout << ... to output your result to STDOUT. | |
* Use cerr << ... to output debugging information to STDERR | |
* ***/ | |
#include <iostream> | |
#include <limits> | |
#include <sstream> | |
#include "exercise.hpp" | |
ContestExerciseImpl::ContestExerciseImpl() : Exercise() {} | |
void ContestExerciseImpl::main() { | |
bool skip = true; | |
size_t count = 0; | |
std::string line; | |
while (std::getline(std::cin, line)) | |
{ | |
if (skip) { | |
skip = false; | |
continue; | |
} | |
if (line.size() < 5) continue; | |
bool breaked = false; | |
for (size_t i = line.size() - 5 ; i != line.size() ; ++i) { | |
if (line[i] < '0' || line[i] > '9') { | |
breaked = true; | |
break; | |
} | |
} | |
if (!breaked) { | |
++count; | |
} | |
} | |
std::cout << count << '\n'; | |
} |
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
// https://demo.isograd.com/runtest/QuestionDisplayer | |
/******* | |
* Read input from STDIN | |
* Use: console.log() to output your result. | |
* Use: console.error() to output debug information into STDERR | |
* ***/ | |
var input = []; | |
readline_object.on("line", (value) => { //Read input values | |
input.push(value); | |
}) | |
//Call ContestResponse when all inputs are read | |
readline_object.on("close", ContestResponse); | |
function readKey() { | |
let result = []; | |
let strKeys = input[1].split(" "); | |
for (let strKey of strKeys) { | |
result.push(parseInt(strKey)); | |
} | |
return result; | |
} | |
function readIntervals() { | |
let interval = []; | |
for (let i = 2 ; i < input.length; ++i) { | |
let splitted = input[i].split(" "); | |
interval.push([parseInt(splitted[0]), parseInt(splitted[1])]); | |
} | |
return interval | |
} | |
function buildMessage(key, intervals) { | |
let message = []; | |
for (let interval of intervals) { | |
let word = 0; | |
for (let i = interval[0]; i <= interval[1] ; ++i) { | |
word = word ^ key[i]; | |
} | |
message.push(word); | |
} | |
return message; | |
} | |
function buildDisplay(message) { | |
let t = []; | |
for (let i = 0 ; i != 256 ; ++i) { | |
t.push(0); | |
} | |
for (let word of message) { | |
t[word] += 1; | |
} | |
return t; | |
} | |
function displayToStr(t) { | |
let s = ""; | |
let first = false; | |
for (let x of t) { | |
if (!first) { | |
first = true; | |
} else { | |
s += " "; | |
} | |
s += x; | |
} | |
return s; | |
} | |
function ContestResponse(){ | |
console.error("====="); | |
console.error(input); | |
const keys = readKey(); | |
const intervals = readIntervals(); | |
const message = buildMessage(keys, intervals); | |
const toDisplay = buildDisplay(message); | |
console.log(displayToStr(toDisplay)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment