Skip to content

Instantly share code, notes, and snippets.

View chermehdi's full-sized avatar
💭
My opinions are my own.

Mehdi Cheracher chermehdi

💭
My opinions are my own.
View GitHub Profile
# A program that reads input from filename
# And prints output to stdout
with open("filename.in", "r") as f:
a, b = map(int, f.readline().split())
print(a * b)
@chermehdi
chermehdi / ReadingInput.java
Last active December 12, 2020 15:25
Ways to read input from files in Competitive programming contests
class Reader {
public static void main(String[] args) {
InputStream in = new FileInputStream("filename.in");
Scanner in = new Scanner(in);
// Using FAST IO
InputReader reader = new InputReader(in);
}
}
// FAST IO
@chermehdi
chermehdi / Explanation.md
Created June 20, 2020 23:49
Explanation of the behaviour of a java exercice.

Answers with a bit of explanation

Note: If some answer does not make sense, or it's not well explained I apologise, please leave a question in the gist.
  • Q2a: Answer -> 4

    • The field was initialised at first with 2, after that a.work() was called which changed the current value of a.x to the return value of calling compute on the result of getX which simply will return b.x, compute is defined for B as v -> v * 2, which made x equal to 2.
  • Q2b: Answer -> 5

@chermehdi
chermehdi / main.cpp
Created June 4, 2020 12:13
A simple graph traversal example: using bfs
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
// Sample input
// 4 4
// 0 1
// 0 2
// 1 3

Mini search engine

Functional requirements

  • Should produce a binary (all dependencies included).

  • Should be able to process 2 command line arguments:

    • URL(required): the starting url of a webpage where the crawler is going to start from.
    • depth(optional, default=20): The depth where the crawler should stop
  • Starting the app should start the crawling process, and also should start an

Alhazn Contest - 01

Contest Descirption

  • This an assesement contest for the group, 16 people participated and 8 have solved at least one problem.
  • Contest URL: alhazn contest

Problem A: Solving for Carrots

  • This problem actually just boils down to printing the second integer read.
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <unordered_map>
#include <vector>
using namespace std;
const int N = 100005;
int cnt[N], ans[N], val[N], size[N], tree[N];
class SegmentTree {
public int modifyOperation(int x, int y) {
return x + y;
}
public int queryOperation(int leftValue, int rightValue) {
return Math.max(leftValue, rightValue);
}
package io.github.chermehdi.main;
import io.github.chermehdi.lib.ArrayUtils;
import io.github.chermehdi.lib.Bits;
import io.github.chermehdi.lib.GraphUtils;
import io.github.chermehdi.lib.externals.SegmentTree;
import io.github.chermehdi.lib.io.InputReader;
import io.github.chermehdi.lib.io.OutputWriter;
import java.util.List;
package io.github.chermehdi.lib.ds;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.function.Supplier;
/**