_id stringlengths 2 5 | text stringlengths 7 10.9k | title stringclasses 1
value |
|---|---|---|
c336 |
class matrixNG {
private:
virtual void consumeTerm(){}
virtual void consumeTerm(int n){}
virtual const bool needTerm(){}
protected: int cfn = 0, thisTerm;
bool haveTerm = false;
friend class NG;
};
class NG_4 : public matrixNG {
private: int a1, a, b1, b, t;
const bool needTerm() {
if... | |
c337 | #include <iostream>
#include <vector>
#include <boost/rational.hpp>
using rational = boost::rational<unsigned long>;
unsigned long floor(const rational& r) {
return r.numerator()/r.denominator();
}
rational calkin_wilf_next(const rational& term) {
return 1UL/(2UL * floor(term) + 1UL - term);
}
std::vector<u... | |
c338 | #include <array>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <vector>
auto init_zc() {
std::array<int, 1000> zc;
zc.fill(0);
zc[0] = 3;
for (int x = 1; x <= 9; ++x) {
zc[x] = 2;
zc[10 * x] = 2;
zc[100 * x] = 2;
for (int y = 10; y <= 90; y += 10) {
... | |
c339 | #include <algorithm>
#include <array>
#include <cassert>
#include <initializer_list>
#include <iostream>
constexpr size_t sp_rows = 3;
constexpr size_t sp_columns = 3;
constexpr size_t sp_cells = sp_rows * sp_columns;
constexpr int sp_limit = 4;
class abelian_sandpile {
friend std::ostream& operator<<(std::ostrea... | |
c340 | #include <array>
#include <iostream>
#include <numeric>
#include <vector>
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::uint128_t;
class magic_number_generator {
public:
magic_number_generator() : magic_(10) {
std::iota(magic_.begin(), magic_.end(), 0);
}
bool next(uint... | |
c341 | #include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;
void PrintContainer(forward_iterator auto start, forward_iterator auto sentinel)
{
for(auto it = start; it != sentinel; ++it)
{
cout << *it << " ";
}
cout << "\n";
}
void FirstFourthFifth(input_iterator auto... | |
c342 | #include <bitset>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
size_t consonants(const std::string& word) {
std::bitset<26> bits;
size_t bit = 0;
for (char ch : word) {
ch = std::tolower(static_ca... | |
c343 | #include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include "prime_sieve.hpp"
int main(int argc, char** argv) {
const char* filename(argc < 2 ? "unixdict.txt" : argv[1]);
std::ifstream in(filename);
if (!in) {
std::cerr << "Cannot ope... | |
c344 | #include <iomanip>
#include <iostream>
#include <gmpxx.h>
using big_int = mpz_class;
class riordan_number_generator {
public:
big_int next();
private:
big_int a0_ = 1;
big_int a1_ = 0;
int n_ = 0;
};
big_int riordan_number_generator::next() {
int n = n_++;
if (n == 0)
return a0_;
... | |
c345 | #include <iomanip>
#include <iostream>
unsigned int divisor_count(unsigned int n) {
unsigned int total = 1;
for (; (n & 1) == 0; n >>= 1)
++total;
for (unsigned int p = 3; p * p <= n; p += 2) {
unsigned int count = 1;
for (; n % p == 0; n /= p)
++count;
total *= ... | |
c346 | #include <array>
#include <iostream>
#include <primesieve.hpp>
class ormiston_triple_generator {
public:
ormiston_triple_generator() {
for (int i = 0; i < 2; ++i) {
primes_[i] = pi_.next_prime();
digits_[i] = get_digits(primes_[i]);
}
}
std::array<uint64_t, 3> next_... | |
c347 | #include <algorithm>
#include <iostream>
#include <vector>
std::vector<unsigned int> divisors(unsigned int n) {
std::vector<unsigned int> result{1};
unsigned int power = 2;
for (; (n & 1) == 0; power <<= 1, n >>= 1)
result.push_back(power);
for (unsigned int p = 3; p * p <= n; p += 2) {
... | |
c348 | #include <iostream>
#include <string>
#include <windows.h>
using namespace std;
typedef unsigned char byte;
enum fieldValues : byte { OPEN, CLOSED = 10, MINE, UNKNOWN, FLAG, ERR };
class fieldData
{
public:
fieldData() : value( CLOSED ), open( false ) {}
byte value;
bool open, mine;
};
class game
{
publi... | |
c349 | #include <iostream>
#include <iomanip>
#include <string>
class oo {
public:
void evolve( int l, int rule ) {
std::string cells = "O";
std::cout << " Rule #" << rule << ":\n";
for( int x = 0; x < l; x++ ) {
addNoCells( cells );
std::cout << std::setw( 40 + ( static... | |
c350 | #include <iomanip>
#include <iostream>
#include <vector>
std::vector<bool> prime_sieve(int limit) {
std::vector<bool> sieve(limit, true);
if (limit > 0)
sieve[0] = false;
if (limit > 1)
sieve[1] = false;
for (int i = 4; i < limit; i += 2)
sieve[i] = false;
for (int p = 3, sq... | |
c351 | #include <iostream>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
template<typename P>
void PrintPayloads(const P &payloads, int index, bool isLast)
{
if(index < 0 || index >= (int)size(payloads)) cout << "null";
else cout << "'" << payloads[index] << "'";
if (!isLast) co... | |
c352 | #include <iomanip>
#include <iostream>
#include <sstream>
#include <utility>
#include <primesieve.hpp>
uint64_t digit_sum(uint64_t n) {
uint64_t sum = 0;
for (; n > 0; n /= 10)
sum += n % 10;
return sum;
}
class honaker_prime_generator {
public:
std::pair<uint64_t, uint64_t> next();
private:... | |
c353 | #include <iomanip>
#include <iostream>
bool is_prime(int n) {
if (n < 2)
return false;
if (n % 2 == 0)
return n == 2;
if (n % 3 == 0)
return n == 3;
for (int p = 5; p * p <= n; p += 4) {
if (n % p == 0)
return false;
p += 2;
if (n % p == 0)
... | |
c354 | #include <iostream>
#include <algorithm>
#include <ctime>
#include <string>
#include <vector>
typedef std::vector<char> vecChar;
class master {
public:
master( size_t code_len, size_t clr_count, size_t guess_count, bool rpt ) {
std::string color = "ABCDEFGHIJKLMNOPQRST";
if( code_len < 4 ) code_l... | |
c355 | #include <algorithm>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <vector>
std::vector<uint64_t> divisors(uint64_t n) {
std::vector<uint64_t> result{1};
uint64_t power = 2;
for (; (n & 1) == 0; power <<= 1, n >>= 1)
result.push_back(power);
for (uint64_t p = 3; p * p <= n;... | |
c356 | #include <algorithm>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using bigram = std::pair<char, char>;
std::multiset<bigram> bigrams(const std::string& phrase) {
std::multiset<bigram> result;
... | |
c371 | #include <windows.h>
#include <string>
#include <complex>
const int BMP_SIZE = 600, ITERATIONS = 512;
const long double FCT = 2.85, hFCT = FCT / 2.0;
class myBitmap {
public:
myBitmap() : pen( NULL ), brush( NULL ), clr( 0 ), wid( 1 ) {}
~myBitmap() {
DeleteObject( pen ); DeleteObject( brush );
... | |
c372 | #include <utility>
#include <iterator>
#include <iostream>
#include <ostream>
#include <algorithm>
#include <iterator>
template<typename ForwardIterator>
std::pair<ForwardIterator, ForwardIterator>
max_subseq(ForwardIterator begin, ForwardIterator end)
{
typedef typename std::iterato... | |
c373 | #include <iostream>
int main()
{
LOOP:
std::cout << "Hello, World!\n";
goto LOOP;
}
| |
c374 | #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
template <typename StringType>
size_t levenshtein_distance(const StringType& s1, const StringType& s2) {
const size_t m = s1.size();
const size_t n = s2.size();
if (m == 0)
return n;
if (n == 0)
... | |
c375 | #include <cstdlib>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <ctime>
#include <iomanip>
int main( ) {
typedef std::vector<std::pair<std::string, double> >::const_iterator SPI ;
typedef std::vector<std::pair<std::string , double> > ProbType ;
ProbType probabilities ... | |
c376 | #include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
int gcd(int a, int b) {
int c;
while (b) {
c = a;
a = b;
b = c % b;
}
return a;
}
int main() {
using intpair = std::pair<int,int>;
std::vector<intpair> pairs = {
{21,15}, {17,23}, {36,... | |
c377 | #include <gmpxx.h>
#include <chrono>
using namespace std;
using namespace chrono;
void agm(mpf_class& rop1, mpf_class& rop2, const mpf_class& op1,
const mpf_class& op2)
{
rop1 = (op1 + op2) / 2;
rop2 = op1 * op2;
mpf_sqrt(rop2.get_mpf_t(), rop2.get_mpf_t());
}
int main(void)
{
auto st = ste... | |
c378 | #include <algorithm>
#include <iostream>
#include <string>
void comb(int N, int K)
{
std::string bitmask(K, 1);
bitmask.resize(N, 0);
do {
for (int i = 0; i < N; ++i)
{
if (bitmask[i]) std::cout << " " << i;
}
std::cout << std::endl;
} while (std::pr... | |
c379 | #include <QApplication>
#include <QMainWindow>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow window;
window.show();
return app.exec();
}
| |
c380 | #include <iostream>
#include <string>
void base2_increment(std::string& s) {
size_t z = s.rfind('0');
if (z != std::string::npos) {
s[z] = '1';
size_t count = s.size() - (z + 1);
s.replace(z + 1, count, count, '0');
} else {
s.assign(s.size() + 1, '0');
s[0] = '1';... | |
c381 | #include <windows.h>
#include <iostream>
#include <string>
using namespace std;
const int PLAYERS = 2, MAX_POINTS = 100;
class player
{
public:
player() { reset(); }
void reset()
{
name = "";
current_score = round_score = 0;
}
string getName() { return name; }
void setName( s... | |
c382 | #include <iostream>
#include <string>
std::string to_roman(int value)
{
struct romandata_t { int value; char const* numeral; };
static romandata_t const romandata[] =
{ 1000, "M",
900, "CM",
500, "D",
400, "CD",
100, "C",
90, "XC",
50, "L",
40, "XL",
... | |
c383 | #include <cstdint>
#include <iomanip>
#include <iostream>
#include <primesieve.hpp>
bool is_prime(uint64_t n) {
if (n < 2)
return false;
if (n % 2 == 0)
return n == 2;
if (n % 3 == 0)
return n == 3;
for (uint64_t p = 5; p * p <= n; p += 4) {
if (n % p == 0)
r... | |
c384 | #include <iostream>
#include <sstream>
#include <set>
bool checkDec(int num) {
std::set<int> set;
std::stringstream ss;
ss << num;
auto str = ss.str();
for (int i = 0; i < str.size(); ++i) {
char c = str[i];
int d = c - '0';
if (d == 0) return false;
if (num % d !=... | |
c385 | #include <iostream>
using std::cout;
int main()
{
for(int bottles(99); bottles > 0; bottles -= 1){
cout << bottles << " bottles of beer on the wall\n"
<< bottles << " bottles of beer\n"
<< "Take one down, pass it around\n"
<< bottles - 1 << " bottles of beer on the wall\n\n";
}
}
| |
c386 | #include<iostream>
using namespace std;
int main()
{
int q,r;
for(q=0;q<16;q++){
for(r=10;r<16;r++){
std::cout<<16*q+r<<" ";
}
}
return 0;
}
| |
c387 | #include <time.h>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
enum color {
red, green, purple
};
enum symbol {
oval, squiggle, diamond
};
enum number {
one, two, three
};
enum shading {
solid, open, striped
};
class card {
public:
card( color ... | |
c388 | #include <vector>
#include <string>
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;
#if 1
typedef unsigned long usingle;
typedef unsigned long long udouble;
const int word_len = 32;
#else
typedef unsigned short usingle;
typedef unsigned long udouble;
const int word_len = 16;
#endif
... | |
c389 | #include <iostream>
bool circle(int x, int y, int c, int r) {
return (r * r) >= ((x = x / 2) * x) + ((y = y - c) * y);
}
char pixel(int x, int y, int r) {
if (circle(x, y, -r / 2, r / 6)) {
return '#';
}
if (circle(x, y, r / 2, r / 6)) {
return '.';
}
if (circle(x, y, -r / 2, r... | |
c390 | struct link
{
link* next;
int data;
};
| |
c391 | #include <iostream>
#include <vector>
#include <numeric>
float sum(const std::vector<float> &array)
{
return std::accumulate(array.begin(), array.end(), 0.0);
}
float square(float x)
{
return x * x;
}
float mean(const std::vector<float> &array)
{
return sum(array) / array.size();
}
float averageSquareDi... | |
c392 | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
typedef unsigned char ubyte;
const auto BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
std::vector<ubyte> encode(const std::vector<ubyte>& source) {
auto it = source.cbegin();
auto end = source.cend();
... | |
c393 | #include <iostream>
#include <locale>
#include <primesieve.hpp>
int main() {
std::cout.imbue(std::locale(""));
const uint64_t limit = 10000000000;
uint64_t max_diff = 0;
primesieve::iterator pi;
uint64_t p1 = pi.next_prime();
for (uint64_t p = 10;;) {
uint64_t p2 = pi.next_prime();
... | |
c394 |
#include <tr1/functional>
#include <iostream>
using namespace std;
using namespace std::tr1;
void first(function<void()> f)
{
f();
}
void second()
{
cout << "second\n";
}
int main()
{
first(second);
}
| |
c395 | #include <iostream>
unsigned int ackermann(unsigned int m, unsigned int n) {
if (m == 0) {
return n + 1;
}
if (n == 0) {
return ackermann(m - 1, 1);
}
return ackermann(m - 1, ackermann(m, n - 1));
}
int main() {
for (unsigned int m = 0; m < 4; ++m) {
for (unsigned int n = 0; n < 10; ++n) {
... | |
c396 | #include <algorithm>
template <typename Iterator>
double median(Iterator begin, Iterator end) {
Iterator middle = begin + (end - begin) / 2;
std::nth_element(begin, middle, end);
if ((end - begin) % 2 != 0) {
return *middle;
} else {
Iterator lower_middle = std::max_element(begin, midd... | |
c397 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const vector<string> MONTHS = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
struct Birthday {
int month, day;
friend ostream &operator<<(ostream &, const Birthday &);
};
ostream ... | |
c398 | #include <iostream>
#include <utility>
using namespace std;
int main(void)
{
cout << "Find a solution to i = 2 * j - 7\n";
pair<int, int> answer;
for(int i = 0; true; i++)
{
for(int j = 0; j < i; j++)
{
if( i == 2 * j - 7)
{
ans... | |
c399 | #include <iostream>
#include <sstream>
#include <vector>
uint64_t ipow(uint64_t base, uint64_t exp) {
uint64_t result = 1;
while (exp) {
if (exp & 1) {
result *= base;
}
exp >>= 1;
base *= base;
}
return result;
}
int main() {
using namespace std;
v... | |
c400 | #include<iostream>
#include<conio.h>
using namespace std;
typedef unsigned long ulong;
int ith_digit_finder(long long n, long b, long i){
while(i>0){
n/=b;
i--;
}
return (n%b);
}
long eeuclid(long m, long b, long *inverse){
long A1 = 1, A2 = 0, A3 = m,
B1 = 0, B... | |
c401 | #include <iostream>
#include <iomanip>
#include <string>
#include <gmpxx.h>
std::string smallest_six(unsigned int n) {
mpz_class pow = 1;
std::string goal = std::to_string(n);
while (pow.get_str().find(goal) == std::string::npos) {
pow *= 6;
}
return pow.get_str();
}
int main() {... | |
c402 | #include <vector>
#include <iostream>
using namespace std;
class ludic
{
public:
void ludicList()
{
_list.push_back( 1 );
vector<int> v;
for( int x = 2; x < 22000; x++ )
v.push_back( x );
while( true )
{
vector<int>::iterator i = v.begin();
... | |
c403 | #include <iostream>
int main()
{
int undefined;
if (undefined == 42)
{
std::cout << "42";
}
if (undefined != 42)
{
std::cout << "not 42";
}
}
| |
c404 | #include <iostream>
unsigned int sum_square_digits(unsigned int n) {
int i,num=n,sum=0;
while (num > 0) {
int digit=num % 10;
num=(num - digit)/10;
sum+=digit*digit;
}
return sum;
}
int main(void... | |
c405 | #include <iostream>
#include <fstream>
#include <set>
#include <sstream>
#include <string>
#include <vector>
std::vector<std::string> longest_substrings_without_repeats(const std::string& str) {
size_t max_length = 0;
std::vector<std::string> result;
size_t length = str.size();
for (size_t offset = 0; ... | |
c406 | #include <iostream>
#include <algorithm>
#include<cstdio>
using namespace std;
void Pascal_Triangle(int size) {
int a[100][100];
int i, j;
for (i = 1; i <= size; i++) {
a[i][1] = a[1][i] = 1;
}
for (i = 2; i <= size; i++) {
for (j = 2; j <= size - i; j++) {
if (a[i - 1][j] == 0 || a[i][j - 1] == 0) ... | |
c407 | #include <assert.h>
#include <cmath>
#include <vector>
#include <iostream>
template<int N> struct MomentsAccumulator_
{
std::vector<double> m_;
MomentsAccumulator_() : m_(N + 1, 0.0) {}
void operator()(double v)
{
double inc = 1.0;
for (auto& mi : m_)
{
mi += inc;
inc *= v;
}
}
};
double Stdev(cons... | |
c408 | #include <algorithm>
#include <array>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <mutex>
#include <random>
#include <thread>
using namespace std;
constexpr int bucket_count = 15;
void equalizer(array<int, bucket_count>& buckets,
array<mutex, bucket_count>& bucket_mutex) {
ra... | |
c409 | #include <iostream>
#include <cmath>
using namespace std;
const string animals[]={"Rat","Ox","Tiger","Rabbit","Dragon","Snake","Horse","Goat","Monkey","Rooster","Dog","Pig"};
const string elements[]={"Wood","Fire","Earth","Metal","Water"};
string getElement(int year)
{
int element = floor((year-4)%10/2);
ret... | |
c410 | #include <deque>
#include <iostream>
int hcseq(int n)
{
static std::deque<int> seq(2, 1);
while (seq.size() < n)
{
int x = seq.back();
seq.push_back(seq[x-1] + seq[seq.size()-x]);
}
return seq[n-1];
}
int main()
{
int pow2 = 1;
for (int i = 0; i < 20; ++i)
{
int pow2next = 2*pow2;
doub... | |
c411 | #include <iostream>
#include <algorithm>
#include <vector>
std::vector<int> findProperDivisors ( int n ) {
std::vector<int> divisors ;
for ( int i = 1 ; i < n / 2 + 1 ; i++ ) {
if ( n % i == 0 )
divisors.push_back( i ) ;
}
return divisors ;
}
int main( ) {
std::vector<int> deficients , perfec... | |
c412 | #include <vector>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <cmath>
bool isPrime ( int number ) {
if ( number <= 1 )
return false ;
if ( number == 2 )
return true ;
for ( int i = 2 ; i <= std::sqrt( number ) ; i++ ) {
if ( number % i == 0 )
ret... | |
c413 | #include <algorithm>
#include <array>
#include <iterator>
#include <limits>
#include <tuple>
namespace detail_ {
constexpr auto digits = std::array{'0','1','2','3','4','5','6','7','8','9'};
template <typename OutputIterator>
constexpr auto encode_run_length(std::size_t n, OutputIterator out)
{
constexpr auto b... | |
c414 | #include <windows.h>
#include <iostream>
#include <string>
using namespace std;
enum states { SEED, GROWING, MOVING, REST };
enum treeStates { NONE, MOVER, TREE };
const int MAX_SIDE = 480, MAX_MOVERS = 511, MAX_CELLS = 15137;
class point
{
public:
point() { x = y = 0; }
point( int a, int... | |
c415 | #include <fstream>
#include <iostream>
#include <locale>
using namespace std;
int main(void)
{
std::locale::global(std::locale(""));
std::cout.imbue(std::locale());
ifstream in("input.txt");
wchar_t c;
while ((c = in.get()) != in.eof())
wcout<<c;
in.close();
return EXIT_... | |
c416 | #include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
size_t table_column_width(const int min, const int max)
{
unsigned int abs_max = std::max(max*max, min*min);
size_t colwidth = 2 + std::log10(abs_max);
if (min < 0 && max > 0)
++colwidth;
... | |
c417 | #include <iostream>
#include <cmath>
#include <cassert>
using namespace std;
inline double Det(double a, double b, double c, double d)
{
return a*d - b*c;
}
bool LineLineIntersect(double x1, double y1,
double x2, double y2,
double x3, double y3,
double x4, double y4,
double &ixOut, double &iyOut)
{
doub... | |
c418 | for (container_type::iterator i = container.begin(); i != container.end(); ++i)
{
std::cout << *i << "\n";
}
| |
c419 | #include <iostream>
#include <string>
void string_has_repeated_character(const std::string& str) {
size_t len = str.length();
std::cout << "input: \"" << str << "\", length: " << len << '\n';
for (size_t i = 0; i < len; ++i) {
for (size_t j = i + 1; j < len; ++j) {
if (str[i] == str[j])... | |
c420 | #include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
int main( ) {
std::vector<int> numbers ;
for ( int i = 1 ; i < 11 ; i++ )
numbers.push_back( i ) ;
double meansquare = sqrt( ( std::inner_product( numbers.begin(), numbers.end(), numbers.begin(), 0 ) ) / static_cast<double>( numbers.si... | |
c421 | #include <iostream>
#include <sstream>
#include <iterator>
#include <climits>
#include <deque>
template<typename OutIter>
bool parse_number_list_with_ranges(std::istream& is, OutIter out)
{
int number;
while (is >> number)
{
*out++ = number;
char c;
if (is >> c)
switch(c)
{
... | |
c422 | #include <algorithm>
#include <iostream>
#include <vector>
const int STX = 0x02;
const int ETX = 0x03;
void rotate(std::string &a) {
char t = a[a.length() - 1];
for (int i = a.length() - 1; i > 0; i--) {
a[i] = a[i - 1];
}
a[0] = t;
}
std::string bwt(const std::string &s) {
for (char c : ... | |
c423 | #include <functional>
#include <iostream>
#include <random>
class BinarySearchTree {
private:
struct Node {
int key;
Node *left, *right;
Node(int k) : key(k), left(nullptr), right(nullptr) {
}
} *root;
public:
BinarySearchTree() : root(nullptr) {
... | |
c424 | #include <fstream>
#include <boost/array.hpp>
#include <string>
#include <cstdlib>
#include <ctime>
#include <sstream>
void makeGap( int gap , std::string & text ) {
for ( int i = 0 ; i < gap ; i++ )
text.append( " " ) ;
}
int main( ) {
boost::array<char , 3> chars = { 'X' , 'Y' , 'Z' } ;
int headgap ... | |
c425 | #include <string>
#include <boost/regex.hpp>
#include <boost/asio.hpp>
#include <vector>
#include <utility>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <iomanip>
struct Sort {
bool operator( ) ( const std::pair<std::string,int> & a , const std::pair<std::string,int> & b ... | |
c426 | #include <iostream>
struct Interval {
int start, end;
bool print;
};
int main() {
Interval intervals[] = {
{2, 1000, true},
{1000, 4000, true},
{2, 10000, false},
{2, 100000, false},
{2, 1000000, false},
{2, 10000000, false},
{2, 100000000, false},
... | |
c427 | template<typename Number>
Number power(Number base, int exponent)
{
int zerodir;
Number factor;
if (exponent < 0)
{
zerodir = 1;
factor = Number(1)/base;
}
else
{
zerodir = -1;
factor = base;
}
Number result(1);
while (exponent != 0)
{
if (exponent % 2 != 0)
{
resul... | |
c428 | #include <iostream>
#include <string>
#include <queue>
#include <utility>
int main() {
std::priority_queue<std::pair<int, std::string> > pq;
pq.push(std::make_pair(3, "Clear drains"));
pq.push(std::make_pair(4, "Feed cat"));
pq.push(std::make_pair(5, "Make tea"));
pq.push(std::make_pair(1, "Solve RC tasks"))... | |
c429 | #include <iomanip>
#include <iostream>
class Date {
private:
int year, month, day;
public:
Date(std::string str) {
if (isValidDate(str)) {
year = atoi(&str[0]);
month = atoi(&str[5]);
day = atoi(&str[8]);
} else {
throw std::exception("Invalid da... | |
c430 | #ifndef TASK_H
#define TASK_H
#include <QWidget>
class QPushButton ;
class QString ;
class QLineEdit ;
class QLabel ;
class QVBoxLayout ;
class QHBoxLayout ;
class MyWidget : public QWidget {
Q_OBJECT
public:
MyWidget( QWidget *parent = 0 ) ;
private slots:
void buttonChange( const QString & ) ;
vo... | |
c431 | #include <iostream>
#include <string>
using namespace std;
int main()
{
string story, input;
while(true)
{
getline(cin, input);
if(input == "\r")
break;
story += input;
}
int begin;
while((begin = story.find("<")) != string::npos)
{
int end = story.find... | |
c432 | #include <iostream>
class T
{
public:
virtual void identify() { std::cout << "I am a genuine T" << std::endl; }
virtual T* clone() { return new T(*this); }
virtual ~T() {}
};
class S: public T
{
public:
virtual void identify() { std::cout << "I am an S" << std::endl; }
virtual S* clone() { return new S(*thi... | |
c433 | #include <algorithm>
#include <cctype>
#include <string>
#include <iostream>
const std::string alphabet("abcdefghijklmnopqrstuvwxyz");
bool is_pangram(std::string s)
{
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
std::sort(s.begin(), s.end());
return std::includes(s.begin(), s.end(), alphabet... | |
c434 | #include <string>
#include <iomanip>
#include <iostream>
#define HEIGHT 16
#define WIDTH 6
#define ASCII_START 32
#define ASCII_END 128
#define SPACE 32
#define DELETE 127
std::string displayAscii(int ascii) {
switch(ascii) {
case SPACE:
return "Spc";
case DELE... | |
c435 | #include <array>
#include <iomanip>
#include <iostream>
#include <vector>
int indexOf(const std::vector<int> &haystack, int needle) {
auto it = haystack.cbegin();
auto end = haystack.cend();
int idx = 0;
for (; it != end; it = std::next(it)) {
if (*it == needle) {
return idx;
... | |
c436 | #include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
bool is_deranged(const std::string& left, const std::string& right)
{
return (left.size() == right.size()) &&
(std::inner_product(left.begin(), left.end(), ri... | |
c437 | #include <iomanip>
#include <iostream>
#include <tuple>
#include <vector>
const std::string DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
std::string encodeNegativeBase(int64_t n, int b) {
if (b < -62 || b > -1) {
throw std::runtime_error("Argument out of range: b");
}
... | |
c438 | #include <algorithm>
#include <iostream>
#include <vector>
std::vector<int> digits(int n) {
std::vector<int> result;
while (n > 0) {
auto rem = n % 10;
result.push_back(rem);
n /= 10;
}
std::reverse(result.begin(), result.end());
return result;
}
bool is_strange(int n) {
... | |
c439 | #include <iostream>
std::string scs(std::string x, std::string y) {
if (x.empty()) {
return y;
}
if (y.empty()) {
return x;
}
if (x[0] == y[0]) {
return x[0] + scs(x.substr(1), y.substr(1));
}
if (scs(x, y.substr(1)).size() <= scs(x.substr(1), y).size()) {
re... | |
c440 | #include <queue>
#include <cassert>
int main()
{
std::queue<int> q;
assert( q.empty() );
q.push(1);
assert( !q.empty() );
assert( q.front() == 1 );
q.push(2);
assert( !q.empty() );
assert( q.front() == 1 );
q.push(3); ... | |
c441 | #include <iostream>
#include <random>
int main()
{
std::random_device rd;
std::uniform_int_distribution<long> dist;
std::cout << "Random Number: " << dist(rd) << std::endl;
}
| |
c442 | #include <iostream>
int countDivisors(int n) {
if (n < 2) return 1;
int count = 2;
for (int i = 2; i <= n/2; ++i) {
if (n%i == 0) ++count;
}
return count;
}
int main() {
int maxDiv = 0, count = 0;
std::cout << "The first 20 anti-primes are:" << std::endl;
for (int n = 1; count... | |
c443 | void move(int n, int from, int to, int via) {
if (n == 1) {
std::cout << "Move disk from pole " << from << " to pole " << to << std::endl;
} else {
move(n - 1, from, via, to);
move(1, from, to, via);
move(n - 1, via, to, from);
}
}
| |
c444 | #include <iostream>
int main()
{
unsigned i = 0;
do
{
std::cout << std::oct << i << std::endl;
++i;
} while(i != 0);
return 0;
}
| |
c445 | #include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <regex>
std::string findExtension ( const std::string & filename ) {
auto position = filename.find_last_of ( '.' ) ;
if ( position == std::string::npos )
return "" ;
else {
std::string extension ( filename.substr... | |
c446 | #include <iostream>
#include <tuple>
class Vector {
private:
double _x, _y, _z;
public:
Vector(double x, double y, double z) : _x(x), _y(y), _z(z) {
}
double getX() {
return _x;
}
double getY() {
return _y;
}
double getZ() {
return _z;
}
dou... | |
c447 | #include <windows.h>
#include <sstream>
#include <iostream>
using namespace std;
class floyds_tri
{
public:
floyds_tri() { lastLineLen = 0; }
~floyds_tri() { killArray(); }
void create( int rows )
{
_rows = rows;
calculateLastLineLen();
display();
}
private:
void killArray()
{
if(... | |
c448 | #include <windows.h>
#include <iostream>
using namespace std;
class calender
{
public:
void drawCalender( int y )
{
year = y;
for( int i = 0; i < 12; i++ )
firstdays[i] = getfirstday( i );
isleapyear();
build();
}
private:
void isleapyear()
{
isleap = false;
if( !( year % 4 ) )
{... | |
c449 | #include <algorithm>
#include <chrono>
#include <iostream>
#include <random>
#include <vector>
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
auto it = v.cbegin();
auto end = v.cend();
os << '[';
if (it != end) {
os << *it;
it = std::next(it... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.