Skip to content

Instantly share code, notes, and snippets.

View stevenRush's full-sized avatar

Eltyshev Evgeny stevenRush

  • Moscow Institute of Physics and Technology
  • Moscow
View GitHub Profile
@stevenRush
stevenRush / gist:10011050
Created April 6, 2014 20:19
Метод ломанных
def task1(a=1, b=2, eps=0.0001): # Метод ломаных
# Определяем коэфициенты. Коэфициенты взяты как четвертый знак курса евро\рубль за 28.03-05.04
coef = (5, 4, 6, 6, 1, 9, 4)
# Определяем функцию
f = lambda x: abs(abs(abs(coef[0]*x*x + coef[1]*x) - abs(coef[2]*x*x-coef[3])) - abs(coef[4]*x*x-coef[5]*x+coef[6]))
# Определяем L
L, M, i = 0, 0, a
while i < b:
M = f(i) / eps
L = max(M, L)
#include <exception>
#include <codecvt>
#include <streambuf>
#include <string>
#include <cerrno>
#include <sstream>
using namespace std;
@stevenRush
stevenRush / gist:9384415
Created March 6, 2014 07:50
Shared mutex upgrade example
boost::shared_mutex _access;
void reader()
{
boost::shared_lock< boost::shared_mutex > lock(_access);
// do work here, without anyone having exclusive access
}
void conditional_writer()
{
boost::upgrade_lock< boost::shared_mutex > lock(_access);
@stevenRush
stevenRush / gist:9183712
Created February 24, 2014 08:11
Simple strategy pattern example with templates
template<class ADVANCE_STRATEGY>
class base_iterator : ADVANCE_STRATEGY
{
private:
int * pointer;
public:
base_iterator & operator++()
{
advance(pointer);
}
@stevenRush
stevenRush / gist:9183687
Created February 24, 2014 08:08
Simple strategy pattern example
class base_iterator
{
private:
int * pointer;
protected:
virtual void advance(int *& pointer) = 0;
public:
base_iterator & operator++()
@stevenRush
stevenRush / gist:7789496
Created December 4, 2013 15:28
Some crazy error handling
#pragma once
#include <cstdio>
#include <cstdarg>
template<typename T>
class result
{
private:
T value;
@stevenRush
stevenRush / gist:6685530
Created September 24, 2013 14:22
1269 from Timus Online Judge
#include <iostream>
#include <string>
#include <unordered_map>
#include <map>
#include <utility>
#include <queue>
#include <stdio.h>
#include <cstdlib>
char st[900001];
@stevenRush
stevenRush / gist:6582078
Created September 16, 2013 15:20
1684. Jack's Last Word
#include <vector>
#include <iostream>
#include <string>
void prefix_function (const std::string & s, std::vector<int> & pi)
{
size_t length = s.length();
pi.resize(length);
for (size_t i = 1; i < length; ++i)
{
@stevenRush
stevenRush / gist:6582028
Last active December 23, 2015 04:39
1354. Palindrome. Again Palindrome
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
void z_function (const std::string & s, std::vector<int> & z)
{
size_t length = s.length();
z.clear();
z.resize(length);
#include <sstream>
#include <string>
#include <iostream>
int main()
{
std::string st("192.255.a.0");
std::istringstream iss(st);
std::string st1;
int count = std::count(st.begin(), st.end(), '.');