Code Monkey home page Code Monkey logo

hse_alogs's Introduction

My contest solving toolset

What is this

In process of studying sometimes we solving contests and I use this template.

Template itself located in main.cpp.

How to use it

First, make sure this code works on your machine:

make --version
clang-10 --version

If acm.math.spbu.ru is not your platform, you can't use optimization.h file, but you can simply copy and paste fast IO from there. Let's solve A+B problem with this template, here is solution:

#include <bits/stdc++.h>
// #include "optimization.h" // only if solving on acm.math.spbu.ru !!!
#define debug(expr)
#ifdef LOCAL
#include "debug.h"
#endif

signed main()
{
#ifdef LOCAL
    freopen("input", "r", stdin);
#endif

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);

    int a, b;
    std::cin >> a >> b;
    int result = a - b;
    debug(res);
    std::cout << result << std::endl;

    return 0;
}

You can put test to input file, if you don't want to type it every time you compile your code. Otherwise, you can compile with make nlocal, then you will be able to put your test in command line by yourself. By default, input read from input. So, I type make in command line and it works like:

gleb@ZenBook:~/Documents/hse/y2/algo/prac$ cat input
7 3
gleb@ZenBook:~/Documents/hse/y2/algo/prac$ make
======= BEGIN =======
4
=======  END  =======
gleb@ZenBook:~/Documents/hse/y2/algo/prac$

How to print-debug

You may notice that we didn't solve A+B problem correctly. So, we want to see out res variable. So we just add debug(res):

int a, b;
std::cin >> a >> b;
int result = a - b;
debug(result);
std::cout << result << std::endl;

And now we type make in CL:

======= BEGIN =======
result: 4
4
=======  END  =======

debug is extremely powerful:

std::map<int, std::pair<float, std::set<std::string>>> weird_1{{1, {0.01, {"hello", "hi"}}}};
debug(weird_1);
std::unordered_multimap<int, std::set<std::pair<int, int>>> weird_2{{2, {{}, {}}}, {}};
debug(weird_2);
std::vector<std::string> long_strings{"no", "sssssssssssssssssssssssssssssssssssssssss", "sdfssssssssssssssssssss", "hello", "hi", "how are you"};
debug(long_strings);
std::vector<std::pair<float, double>> short_strings{{1, 2}, {3, 4}};
debug(short_strings);

We getting pretty result:

======= BEGIN =======
weird_1: {1: (0.010000, ["hello", "hi"])}
weird_2: [(0, []), (2, [(0, 0)])]
long_strings: ["no",
"sssssssssssssssssssssssssssssssssssssssss",
"sdfssssssssssssssssssss",
"hello",
"hi",
"how are you"]
short_strings: [(1.000000, 2.000000), (3.000000, 4.000000)]
=======  END  =======

Works with a lot of STL containers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.