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
// Origin: https://stackoverflow.com/questions/22983008/how-to-print-justified-text-in-the-console-using-modern-c | |
#include <iostream> | |
#include <iomanip> | |
#include <sstream> | |
#include <list> | |
#include <iterator> | |
const int pageWidth = 78; | |
typedef std::list<std::string> WordList; | |
typedef void (*PrintLineFunction)( const std::string ); |
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
# coding: utf-8 | |
# python 2.x | |
# Печать всех подмножеств множетсва {1, 2, ..., N} | |
def print_subsets(n, k = 1, s = ""): | |
print "{" + s + "}" # С пустым множеством | |
for i in range(k, n + 1): | |
#print "{" + s + ("," if s else "") + str(i) + "}" # Без пустого множества | |
print_subsets(n, i + 1, s + ("," if s else "") + str(i)) |
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
# coding: utf-8 | |
# python 2.x | |
# Рекурсивное разложение числа на слагаемые | |
def print_sum(n, k = 1, s = ""): | |
print s + ("+" if s else "") + str(n) # Вывод с данным числом | |
for i in range(k, n / 2 + 1): | |
#print s + ("+" if s else "") + str(i) + "+" + str(n - i) # Вывод без данного числа | |
print_sum(n - i, i, s + ("+" if s else "") + str(i)) |
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
// Запись ключей (-a, -b и т.п.) из аргументов командной строки в set of char | |
Program CommandLineKeys; | |
var | |
keys: set of Char; | |
s: String; | |
i: Integer; | |
begin | |
keys := []; | |
// Разбор командной строки |
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
// Разбор строки на лексемы/токены | |
#include <stdio.h> | |
#define BUF 128 | |
int is_delimiter(char c) | |
{ | |
return (c == ' ' || c == '\t'); | |
} |
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
// Разбор строки с числами в массив | |
Program ParseString; | |
// Разделители | |
function is_delimiter(c: Char): Boolean; | |
begin | |
is_delimiter := (c = ' ') or (c = ','); | |
end; | |
var |