Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
My opinions are my own.

Mehdi Cheracher chermehdi

💭
My opinions are my own.
View GitHub Profile
View test.py
# 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 Dec 12, 2020
Ways to read input from files in Competitive programming contests
View ReadingInput.java
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 Jun 20, 2020
Explanation of the behaviour of a java exercice.
View Explanation.md

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 Jun 4, 2020
A simple graph traversal example: using bfs
View main.cpp
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
// Sample input
// 4 4
// 0 1
// 0 2
// 1 3
View search_engine.md

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

View editorial-01.md

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.
View main.cpp
#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];
View SegmentTree.java
class SegmentTree {
public int modifyOperation(int x, int y) {
return x + y;
}
public int queryOperation(int leftValue, int rightValue) {
return Math.max(leftValue, rightValue);
}
View SubtreesAndPaths.java
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;
View CountingMap.java
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;
/**