_id stringlengths 2 5 | text stringlengths 7 10.9k | title stringclasses 1
value |
|---|---|---|
c450 | #include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>
template<typename I>
void mark_composites(I start, I end)
{
std::fill(start, end, 0);
for (auto it = start + 1; it != end; ++it)
{
if (*it == 0)
{
auto prime = std::distance(start, it) + 1;
... | |
c451 | #include <iterator>
#include <algorithm>
#include <functional>
template<typename T>
T median(T t1, T t2, T t3)
{
if (t1 < t2)
{
if (t2 < t3)
return t2;
else if (t1 < t3)
return t3;
else
return t1;
}
else
{
if (t1 < t3)
return t1;
else if (t2 < t3)
return ... | |
c452 | #include <string>
using std::string;
int main()
{
string s = "Hello, world!";
string::size_type length = s.length();
string::size_type size = s.size();
string::size_type bytes = s.length() * sizeof(string::value_type);
}
| |
c453 | #include <iomanip>
#include <iostream>
#include <utility>
auto min_max_prime_factors(unsigned int n) {
unsigned int min_factor = 1;
unsigned int max_factor = 1;
if ((n & 1) == 0) {
while ((n & 1) == 0)
n >>= 1;
min_factor = 2;
max_factor = 2;
}
for (unsigned int ... | |
c454 |
#include <cstdlib>
#include <iostream>
#include <Poco/Net/SMTPClientSession.h>
#include <Poco/Net/MailMessage.h>
using namespace Poco::Net;
int main (int argc, char **argv)
{
try
{
MailMessage msg;
msg.addRecipient (MailRecipient (MailRecipient::PRIMARY_RECIPIENT,
... | |
c455 | #include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
double result;
double capacity = 15;
int NumberOfItems;
int number;
struct items
{
char name[32];
double weight;
double price;
double m;
} item[256];
bool cmp(items a,items b)
{
return a.price/a.weight > b.price/b.weig... | |
c456 | int* pointer2(&var);
| |
c457 | #include <iostream>
#include <vector>
#ifdef HAVE_BOOST
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int integer;
#else
typedef unsigned int integer;
#endif
auto make_bell_triangle(int n) {
std::vector<std::vector<integer>> bell(n);
for (int i = 0; i < n; ++i)
bell[i]... | |
c458 | #include <iostream>
bool gapful(int n) {
int m = n;
while (m >= 10)
m /= 10;
return n % ((n % 10) + 10 * (m % 10)) == 0;
}
void show_gapful_numbers(int n, int count) {
std::cout << "First " << count << " gapful numbers >= " << n << ":\n";
for (int i = 0; i < count; ++n) {
if (gapfu... | |
c459 | #include <sstream>
using namespace std;
bool isNumeric( const char* pszInput, int nNumberBase )
{
istringstream iss( pszInput );
if ( nNumberBase == 10 )
{
double dTestSink;
iss >> dTestSink;
}
else if ( nNumberBase == 8 || nNumberBase == 16 )
{
int nTestSink;
iss >> ( ( nNumberBase == 8 ) ? oct : hex... | |
c460 | #include <windows.h>
#include <sstream>
#include <ctime>
const float PI = 3.1415926536f, TWO_PI = 2.f * PI;
class vector2
{
public:
vector2( float a = 0, float b = 0 ) { set( a, b ); }
void set( float a, float b ) { x = a; y = b; }
void rotate( float r ) {
float _x = x, _y = y,
s = s... | |
c461 | #include <istream>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <iterator>
template<class OutIt>
void read_words(std::istream& is, OutIt dest)
{
std::string word;
while (is >> word)
{
*dest = word;
}
}
template<class OutIt>
void read_lines(std::istream& is, ... | |
c462 | #include <fstream>
#include <iterator>
#include <boost/regex.hpp>
#include <string>
#include <iostream>
int main( int argc , char *argv[ ] ) {
boost::regex to_be_replaced( "Goodbye London\\s*!" ) ;
std::string replacement( "Hello New York!" ) ;
for ( int i = 1 ; i < argc ; i++ ) {
std::ifstream infile (... | |
c463 | #include <iomanip>
#include <iostream>
#include <sstream>
#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);
}
while (... | |
c464 | #include <complex>
#include <iostream>
#include <valarray>
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
void fft(CArray& x)
{
const size_t N = x.size();
if (N <= 1) return;
CArray even = x[std::slice(0, N/2, 2)];
CArra... | |
c465 | #include <iostream>
#include <vector>
int main() {
std::vector<int> a;
a.push_back(1);
a.push_back(2);
a.push_back(1);
a.push_back(3);
a.push_back(2);
std::vector<int> b;
b.push_back(1);
b.push_back(2);
b.push_back(0);
b.push_back(4);
b.push_back(4);
b.push_back(0);
b.push_back(0);
b.push... | |
c466 |
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
#include <iostream>
#include <vector>
typedef boost::rational<boost::multiprecision::int1024_t> rational;
rational bernoulli(size_t n) {
auto out = std::vector<rati... | |
c467 | #include <vector>
#include <iostream>
#include <stdexcept>
using namespace std;
typedef std::pair<double, double> TriPoint;
inline double Det2D(TriPoint &p1, TriPoint &p2, TriPoint &p3)
{
return +p1.first*(p2.second-p3.second)
+p2.first*(p3.second-p1.second)
+p3.first*(p1.second-p2.second);
}
void CheckTriWind... | |
c468 | #include <afx.h>
| |
c469 | #include <iostream>
#include <random>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
void printStars ( int number ) {
if ( number > 0 ) {
for ( int i = 0 ; i < number + 1 ; i++ )
std::cout << '*' ;
}
std::cout << '\n' ;
}
int main( int argc , char *argv[] ) {
const in... | |
c470 | #include <algorithm>
#include <iostream>
#include <vector>
std::vector<uint64_t> primes;
std::vector<uint64_t> smallPrimes;
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 <... | |
c471 | #include <string>
#include <regex>
#include <algorithm>
#include <numeric>
#include <sstream>
bool CheckFormat(const std::string& isin)
{
std::regex isinRegEpx(R"([A-Z]{2}[A-Z0-9]{9}[0-9])");
std::smatch match;
return std::regex_match(isin, match, isinRegEpx);
}
std::string CodeISIN(const std::string& isin)
{
std... | |
c472 | #include <map>
#include <vector>
#include <iostream>
#include <fstream>
#include <utility>
#include <functional>
#include <string>
#include <sstream>
#include <algorithm>
#include <cctype>
class CSV
{
public:
CSV(void) : m_nCols( 0 ), m_nRows( 0 )
{}
bool open( const char* filename, char delim = ',' )
... | |
c473 | #include <iostream>
#include <cmath>
#ifdef M_E
static double euler_e = M_E;
#else
static double euler_e = std::exp(1);
#endif
#ifdef M_PI
static double pi = M_PI;
#else
static double pi = std::acos(-1);
#endif
int main()
{
std::cout << "e = " << euler_e
<< "\npi = " << pi
<< "\nsqrt(2) = ... | |
c474 | #include <algorithm>
#include <vector>
#include <iostream>
#include <string>
typedef unsigned char byte;
class world {
public:
world( int x, int y ) : _wid( x ), _hei( y ) {
int s = _wid * _hei * sizeof( byte );
_cells = new byte[s];
memset( _cells, 0, s );
}
~world() {
de... | |
c475 | #include <stdint.h>
#include <string>
#include <memory>
#include <iostream>
#include <deque>
#include <unordered_map>
#include <algorithm>
#include <iterator>
using namespace std;
class LCS {
protected:
class Pair {
public:
uin... | |
c476 | #include <iostream>
#include <string>
void all_characters_are_the_same(const std::string& str) {
size_t len = str.length();
std::cout << "input: \"" << str << "\", length: " << len << '\n';
if (len > 0) {
char ch = str[0];
for (size_t i = 1; i < len; ++i) {
if (str[i] != ch) {
... | |
c477 | #include <fstream>
#include <iostream>
#include <numeric>
#include <unistd.h>
#include <vector>
std::vector<size_t> get_cpu_times() {
std::ifstream proc_stat("/proc/stat");
proc_stat.ignore(5, ' ');
std::vector<size_t> times;
for (size_t time; proc_stat >> time; times.push_back(time));
return time... | |
c478 | #include <windows.h>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
cout <<
" ______ ______ " << endl <<
" _____ _____|\\ \\ _____|\\ \\ " << endl <<
" _____\\ \\_ / / | | / / | |" << endl <<
" / ... | |
c479 | #include <cassert>
#include <cmath>
#include <iostream>
#include <valarray>
template <typename scalar_type> class matrix {
public:
matrix(size_t rows, size_t columns) : rows_(rows), columns_(columns) {
elements_.resize(rows * columns);
}
matrix(size_t rows, size_t columns, scalar_type value)
... | |
c480 | #include <windows.h>
#include <list>
#include <iostream>
using namespace std;
class point
{
public:
int x, y;
point() { x = y = 0; }
point( int a, int b ) { x = a; y = b; }
void set( int a, int b ) { x = a; y = b; }
};
class rndCircle
{
public:
void draw()
{
createPoint... | |
c481 | #include <fstream>
#include <iostream>
#include <string>
#include <cstdlib>
#include <list>
void deleteLines( const std::string & , int , int ) ;
int main( int argc, char * argv[ ] ) {
if ( argc != 4 ) {
std::cerr << "Error! Invoke with <deletelines filename startline skipnumber>!\n" ;
return 1 ;
}
... | |
c482 | #include <vector>
#include <iostream>
#include <cmath>
#include <utility>
#include <map>
#include <iomanip>
bool isPrime( int i ) {
int stop = std::sqrt( static_cast<double>( i ) ) ;
for ( int d = 2 ; d <= stop ; d++ )
if ( i % d == 0 )
return false ;
return true ;
}
class Compare {
public :
Compa... | |
c483 | #include <iostream>
using namespace std;
template<class T>
class Generator
{
public:
virtual T operator()() = 0;
};
template<class T, T P>
class PowersGenerator: Generator<T> {};
template<int P>
class PowersGenerator<int, P>: Generator<int>
{
public:
int i;
PowersGenerator() { i = 1; }
virtual int operator... | |
c484 | #include <cassert>
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <utility>
#include <vector>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlerror.h>
#include <libxml/xmlsave.h>
#include <libxml/xmlstring.h>
#include <libxml/xmlversion.h>
#ifndef LIBXML_TREE_ENABLED
# ... | |
c485 | #include <iostream>
#include <vector>
template<typename T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& c) {
auto it = c.cbegin();
auto end = c.cend();
out << '[';
if (it != end) {
out << *it;
it = std::next(it);
}
while (it != end) {
out << ", " <... | |
c486 | #include <cassert>
#include <iomanip>
#include <iostream>
#include <vector>
template <typename scalar_type> class matrix {
public:
matrix(size_t rows, size_t columns)
: rows_(rows), columns_(columns), elements_(rows * columns) {}
matrix(size_t rows, size_t columns,
const std::initializer_list<s... | |
c487 | #include <iostream>
#include <sstream>
int main(int argc, char *argv[]) {
using namespace std;
#if _WIN32
if (argc != 5) {
cout << "Usage : " << argv[0] << " (type) (id) (source string) (description>)\n";
cout << " Valid types: SUCCESS, ERROR, WARNING, INFORMATION\n";
} else {
... | |
c488 | #include <random>
#include <functional>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
random_device seed;
mt19937 engine(seed());
normal_distribution<double> dist(1.0, 0.5);
auto rnd = bind(dist, engine);
vector<double> v(1000);
generate(v.begin(), v.end(), rnd);
return 0;
}
| |
c489 | #if !defined __ALGORITHMS_H__
#define __ALGORITHMS_H__
namespace rosetta
{
namespace catalanNumbers
{
namespace detail
{
class Factorial
{
public:
unsigned long long operator()(unsigned n)const;
};
class BinomialCoefficient
{
public:
... | |
c490 | #include <iomanip>
#include <iostream>
#include <vector>
std::vector<bool> prime_sieve(size_t limit) {
std::vector<bool> sieve(limit, true);
if (limit > 0)
sieve[0] = false;
if (limit > 1)
sieve[1] = false;
for (size_t i = 4; i < limit; i += 2)
sieve[i] = false;
for (size_t ... | |
c491 | #include <chrono>
#include <iostream>
#include <sstream>
#include <utility>
#include <primesieve.hpp>
#include <gmpxx.h>
using big_int = mpz_class;
bool is_probably_prime(const big_int& n) {
return mpz_probab_prime_p(n.get_mpz_t(), 30) != 0;
}
class prime_fibonacci_generator {
public:
prime_fibonacci_generat... | |
c492 | #include <iostream>
#include <map>
#include <random>
std::default_random_engine generator;
std::uniform_int_distribution<int> dice(1, 6);
int rollDice() {
return dice(generator);
}
const bool sixesThrowAgain = true;
const std::map<int, int> snl{
{4, 14},
{9, 31},
{17, 7},
{20, 38},
{28, 84},
... | |
c493 | #include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
int main()
{
const char logfilename[] = "mlijobs.txt";
std::ifstream logfile(logfilename);
if (!logfile.is_open())
{
std::cerr << "Error opening: " << logfilename << "\n";
return -1;
}
... | |
c494 | #include <sstream>
const int TABLE[][10] = {
{0, 3, 1, 7, 5, 9, 8, 6, 4, 2},
{7, 0, 9, 2, 1, 5, 4, 8, 6, 3},
{4, 2, 0, 6, 8, 7, 1, 3, 5, 9},
{1, 7, 5, 0, 9, 8, 3, 4, 2, 6},
{6, 1, 2, 3, 0, 4, 5, 9, 7, 8},
{3, 6, 7, 4, 2, 0, 9, 5, 8, 1},
{5, 8, 6, 9, 7, 2, 0, 1, 3, 4},
{8, 9, 4, 5, 3, 6, 2, 0, 1, 7},
{9, 4, 3,... | |
c495 |
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <gmpxx.h>
using integer = mpz_class;
class unsigned_lah_numbers {
public:
integer get(int n, int k);
private:
std::map<std::pair<int, int>, integer> cache_;
};
integer unsigned_lah_numbers::get(int n, int k) {
if (k == ... | |
c496 | #include <iostream>
#include <sstream>
#include <iterator>
#include <vector>
using namespace std;
struct node
{
int val;
unsigned char neighbors;
};
class hSolver
{
public:
hSolver()
{
dx[0] = -1; dx[1] = 0; dx[2] = 1; dx[3] = -1; dx[4] = 1; dx[5] = -1; dx[6] = 0; dx[7] = 1;
dy[0] = -1; dy[1] = -... | |
c497 | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
static void printVerse(const std::string& name) {
std::string x = name;
std::transform(x.begin(), x.end(), x.begin(), ::tolower);
x[0] = toupper(x[0]);
std::string y;
switch (x[0]) {
case 'A':
case 'E':
case '... | |
c498 | #include <algorithm>
#include <complex>
#include <iomanip>
#include <iostream>
std::complex<double> inv(const std::complex<double>& c) {
double denom = c.real() * c.real() + c.imag() * c.imag();
return std::complex<double>(c.real() / denom, -c.imag() / denom);
}
class QuaterImaginary {
public:
QuaterImagi... | |
c499 |
#include <vector>
#include <iostream>
#include <iomanip>
#include <thread>
#include <future>
static void print(const std::vector<int> &pos)
{
for (int i = 0; i < pos.size(); i++) {
std::cout << std::setw(3) << char('a' + i);
}
std::cout << '\n';
for (int row = 0; row < pos.size(); row++) {
int col = p... | |
c500 | #include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>
std::vector<int> divisors(int n) {
std::vector<int> divs{ 1 };
std::vector<int> divs2;
for (int i = 2; i*i <= n; i++) {
if (n%i == 0) {
int j = n / i;
divs.push_back(i);
... | |
c501 | #include <array>
#include <iostream>
#include <list>
#include <map>
#include <vector>
int main()
{
auto myNumbers = std::vector<std::string>{"one", "two", "three", "four"};
auto myColors = std::vector<std::string>{"red", "green", "blue"};
auto myArray = std::array<std::vector<std::string>, 2>{myNumber... | |
c502 | #include <iostream>
typedef unsigned long long bigInt;
using namespace std;
class m35
{
public:
void doIt( bigInt i )
{
bigInt sum = 0;
for( bigInt a = 1; a < i; a++ )
if( !( a % 3 ) || !( a % 5 ) ) sum += a;
cout << "Sum is " << sum << " for n = " << i << endl << endl;
}
void doIt_b... | |
c503 | #include <iomanip>
#include <iostream>
#include <tuple>
typedef std::tuple<double,double> coeff_t;
typedef coeff_t (*func_t)(int);
double calc(func_t func, int n)
{
double a, b, temp = 0;
for (; n > 0; --n) {
std::tie(a, b) = func(n);
temp = b / (a + temp);
}
std::tie(a, b) = func(0)... | |
c505 | #include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
double arcLength(double radius, double angle1, double angle2) {
return (360.0 - abs(angle2 - angle1)) * M_PI * radius / 180.0;
}
int main() {
auto al = arcLength(10.0, 10.0, 120.0);
std::cout << "arc length: " << al << '\n';
return 0;
}
| |
c506 | #include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <sstream>
std::array<std::string, 6> games{ "12", "13", "14", "23", "24", "34" };
std::string results = "000000";
int fromBase3(std::string num) {
int out = 0;
for (auto c : num) {
int d = c - '0';
out = 3 * ... | |
c507 | #include <fstream>
#include <iostream>
#include <set>
#include <string>
int main() {
std::ifstream input("unixdict.txt");
if (input) {
std::set<std::string> words;
std::string word;
size_t count = 0;
while (input >> word) {
std::string drow(word.rbegin(), word.re... | |
c508 | #include <boost/iterator/counting_iterator.hpp>
#include <algorithm>
int factorial(int n)
{
return std::accumulate(boost::counting_iterator<int>(1), boost::counting_iterator<int>(n+1), 1, std::multiplies<int>());
}
| |
c509 | include <vector>
#include <algorithm>
#include <string>
#include <iostream>
int main( ) {
std::vector<std::string> myStrings { "prepended to" , "my string" } ;
std::string prepended = std::accumulate( myStrings.begin( ) ,
myStrings.end( ) , std::string( "" ) , []( std::string a ,
std::string b ) { retur... | |
c510 | #include <iostream>
#include <cstdint>
#include <vector>
#include "prime_sieve.hpp"
using integer = uint32_t;
using vector = std::vector<integer>;
void print_vector(const vector& vec) {
if (!vec.empty()) {
auto i = vec.begin();
std::cout << '(' << *i;
for (++i; i != vec.end(); ++i)
... | |
c511 | #include <iostream>
#include <string>
#include <vector>
void print_menu(const std::vector<std::string>& terms)
{
for (size_t i = 0; i < terms.size(); i++) {
std::cout << i + 1 << ") " << terms[i] << '\n';
}
}
int parse_entry(const std::string& entry, int max_number)
{
int number = std::stoi(entry)... | |
c512 |
#include <iostream>
using std::cout;
using std::endl;
#include <boost/array.hpp>
#include <boost/circular_buffer.hpp>
class Subtractive_generator {
private:
static const int param_i = 55;
static const int param_j = 24;
static const int initial_load = 219;
static const int mod = 1e9;
boost::circu... | |
c513 |
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream file("../include/earthquake.txt");
int count_quake = 0;
int column = 1;
string value;
double size_quake;
string row = "";
while(file >> value)
{
if(column == 3)
{
... | |
c514 |
#include <algorithm>
#include <iostream>
#include <list>
#include <string>
#include <vector>
struct noncopyable {
noncopyable() {}
noncopyable(const noncopyable&) = delete;
noncopyable& operator=(const noncopyable&) = delete;
};
template <typename T>
class tarjan;
template <typename T>
class vertex :... | |
c515 | #include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
const double EPSILON = 1.0e-15;
unsigned long long fact = 1;
double e = 2.0, e0;
int n = 2;
do {
e0 = e;
fact *= n++;
e += 1.0 / fact;
}
while (fabs(e - e0) >= EPSILON);
co... | |
c516 | #include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
const std::string CHR[] = { "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz",
"0123456789", "!\"#$%&'()*+,-./:;<=>?@[]^_{|}~" };
const std::string UNS = "O0l1I5S2Z";
std::string createPW( int len, bool s... | |
c517 | #include <iostream>
class U0 {};
class U1 {};
void baz(int i)
{
if (!i) throw U0();
else throw U1();
}
void bar(int i) { baz(i); }
void foo()
{
for (int i = 0; i < 2; i++)
{
try {
bar(i);
} catch(U0 e) {
std::cout<< "Exception U0 caught\n";
}
}
}
int ma... | |
c518 | #include "Core/Core.h"
using namespace Upp;
CONSOLE_APP_MAIN
{
JsonArray a;
a << Json("name", "John")("phone", "1234567") << Json("name", "Susan")("phone", "654321");
String txt = ~a;
Cout() << txt << '\n';
Value v = ParseJSON(txt);
for(int i = 0; i < v.GetCount(); i++)
Cout() << v[i]["name"] << ' ' << v[i]["... | |
c519 | #include <algorithm>
#include <string>
#include <iostream>
template<typename char_type>
std::basic_string<char_type> squeeze(std::basic_string<char_type> str, char_type ch) {
auto i = std::unique(str.begin(), str.end(),
[ch](char_type a, char_type b) { return a == ch && b == ch; });
str.erase(i, str.en... | |
c522 | #include <iostream>
#include <set>
#include <algorithm>
#include <iterator>
#include <string>
using namespace std;
int main( ) {
string setA[] = { "John", "Bob" , "Mary", "Serena" };
string setB[] = { "Jim" , "Mary", "John", "Bob" };
set<string>
firstSet( setA , setA + 4 ),
secondSet( setB ,... | |
c523 | void Line( float x1, float y1, float x2, float y2, const Color& color )
{
const bool steep = (fabs(y2 - y1) > fabs(x2 - x1));
if(steep)
{
std::swap(x1, y1);
std::swap(x2, y2);
}
if(x1 > x2)
{
std::swap(x1, x2);
std::swap(y1, y2);
}
const float dx = x2 - x1;
const float dy = ... | |
c524 | #include <iostream>
#include <vector>
#include <iterator>
class Hofstadter
{
public:
static int F(int n) {
if ( n == 0 ) return 1;
return n - M(F(n-1));
}
static int M(int n) {
if ( n == 0 ) return 0;
return n - F(M(n-1));
}
};
using namespace std;
int main()
{
int i;
vector<int> ra, rb;
... | |
c525 | #include <iostream>
#include <vector>
class Ham {
private:
std::vector<unsigned int> _H, _hp, _hv, _x;
public:
bool operator!=(const Ham& other) const {return true;}
Ham begin() const {return *this;}
Ham end() const {return *this;}
unsigned int operator*() const {return _x.back();}
Ham(const std::vecto... | |
c526 | #include <iostream>
#include <cmath>
#include <optional>
#include <vector>
using namespace std;
template <typename T>
auto operator>>(const optional<T>& monad, auto f)
{
if(!monad.has_value())
{
return optional<remove_reference_t<decltype(*f(*monad))>>();
}
return f(*monad)... | |
c527 |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <limits>
#include <iostream>
#include <vector>
#include <math.h>
class Vector;
class Matrix {
public:
Matrix() : m(0), n(0), data(nullptr) {}
Matrix(int m_, int n_) : Matrix() {
m = m_;
n = n_;
allocate(m_,n_);
}
Mat... | |
c528 | int val = 0;
do{
val++;
std::cout << val << std::endl;
}while(val % 6 != 0);
| |
c529 | #include <cmath>
#include <iostream>
using namespace std;
double getDifference(double b1, double b2) {
double r = fmod(b2 - b1, 360.0);
if (r < -180.0)
r += 360.0;
if (r >= 180.0)
r -= 360.0;
return r;
}
int main()
{
cout << "Input in -180 to +180 range" << endl;
cout << getDifference(20.0, 45.0) << endl;
... | |
c530 | #include <iomanip>
#include <iostream>
#include <cmath>
bool approxEquals(double a, double b, double e) {
return fabs(a - b) < e;
}
void test(double a, double b) {
constexpr double epsilon = 1e-18;
std::cout << std::setprecision(21) << a;
std::cout << ", ";
std::cout << std::setprecision(21) << b;... | |
c531 | #include <cmath>
#include <iostream>
double vdc(int n, double base = 2)
{
double vdc = 0, denom = 1;
while (n)
{
vdc += fmod(n, base) / (denom *= base);
n /= base;
}
return vdc;
}
int main()
{
for (double base = 2; base < 6; ++base)
{
std::cout << "Base " << base ... | |
c532 | #include <string>
using namespace std;
string s1="abcd";
string s2="abab";
string s3="ab";
s1.compare(0,s3.size(),s3)==0;
s1.compare(s1.size()-s3.size(),s3.size(),s3)==0;
s1.find(s2)
int loc=s2.find(s3)
loc=s2.find(s3,loc+1)
| |
c533 | #include <charconv>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <utility>
#include <variant>
using namespace std;
string file_to_string (const ... | |
c534 | #include <iostream>
using namespace std;
class SudokuSolver {
private:
int grid[81];
public:
SudokuSolver(string s) {
for (unsigned int i = 0; i < s.length(); i++) {
grid[i] = (int) (s[i] - '0');
}
}
void solve() {
try {
placeNumber(0);
cou... | |
c535 | #include <iostream>
#include <fstream>
#include <vector>
typedef unsigned char byte;
using namespace std;
const unsigned m1 = 63 << 18, m2 = 63 << 12, m3 = 63 << 6;
class base64
{
public:
base64() { char_set = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; }
string encode( vector<byte> v... | |
c536 | #include <iostream>
#include <istream>
#include <ostream>
#include <fstream>
#include <cstdlib>
#include <string>
std::string rot13(std::string s)
{
static std::string const
lcalph = "abcdefghijklmnopqrstuvwxyz",
ucalph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
std::string result;
std::string::size_type pos;
... | |
c537 | #include <iostream>
#include <string>
#include <vector>
const std::vector<std::pair<std::string, std::string>> conditions = {
{"Printer prints", "NNNNYYYY"},
{"A red light is flashing", "YYNNYYNN"},
{"Printer is recognized by computer", "NYNYNYNY"}
};
const std::vector<std::pair<std::string, std::string>>... | |
c538 | #include <iostream>
#include <string>
using namespace std;
class Vigenere
{
public:
string key;
Vigenere(string key)
{
for(int i = 0; i < key.size(); ++i)
{
if(key[i] >= 'A' && key[i] <= 'Z')
this->key += key[i];
else if(key[i] >= 'a' && key[i] <= 'z')
this->key += key[i] + '... | |
c539 | #include <iostream>
#include <boost/date_time/posix_time/posix_time.hpp>
int main( ) {
boost::posix_time::ptime t ( boost::posix_time::second_clock::local_time( ) ) ;
std::cout << to_simple_string( t ) << std::endl ;
return 0 ;
}
| |
c540 | #include <time.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <deque>
class riffle
{
public:
void shuffle( std::deque<int>* v, int tm )
{
std::deque<int> tmp;
bool fl;
size_t len;
std::deque<int>::iterator it;
copyTo( v, &tmp );
for( int t = 0; t < tm; t++ )
{
std:... | |
c541 | #include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
#include <vector>
const int n = 61;
std::vector<int> l{ 0, 1 };
int fusc(int n) {
if (n < l.size()) return l[n];
int f = (n & 1) == 0 ? l[n >> 1] : l[(n - 1) >> 1] + l[(n + 1) >> 1];
l.push_back(f);
return f;
}
int main() {
... | |
c542 | #include <iostream>
#include <vector>
using namespace std;
typedef unsigned long long bigint;
class josephus
{
public:
bigint findSurvivors( bigint n, bigint k, bigint s = 0 )
{
bigint i = s + 1;
for( bigint x = i; x <= n; x++, i++ )
s = ( s + k ) % i;
return s;
}
void getExecutionList( bi... | |
c543 | #include <thread>
#include <iostream>
#include <vector>
#include <random>
#include <chrono>
int main()
{
std::random_device rd;
std::mt19937 eng(rd());
std::uniform_int_distribution<> dist(1,1000);
std::vector<std::thread> threads;
for(const auto& str: {"Enjoy\n", "Rosetta\n", "Code\n"}) {
std::c... | |
c544 | #include <time.h>
#include <iostream>
#include <vector>
using namespace std;
class cSort
{
public:
void doIt( vector<unsigned> s )
{
sq = s; display(); c_sort();
cout << "writes: " << wr << endl; display();
}
private:
void display()
{
copy( sq.begin(), sq.end(), ostream_iterator<unsigned>( std... | |
c545 | #include <vector>
#include <iostream>
using namespace std;
void Filter(const vector<float> &b, const vector<float> &a, const vector<float> &in, vector<float> &out)
{
out.resize(0);
out.resize(in.size());
for(int i=0; i < in.size(); i++)
{
float tmp = 0.;
int j=0;
out[i] = 0.f;
for(j=0; j < b.size(); j++)... | |
c546 | #include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <unordered_map>
#include <vector>
int main(int ac, char** av) {
std::ios::sync_with_stdio(false);
int head = (ac > 1) ? std::atoi(av[1]) : 10;
std::istreambuf_iterator<char> it(std::cin),... | |
c547 | #include <iostream>
bool isSemiPrime( int c )
{
int a = 2, b = 0;
while( b < 3 && c != 1 )
{
if( !( c % a ) )
{ c /= a; b++; }
else a++;
}
return b == 2;
}
int main( int argc, char* argv[] )
{
for( int x = 2; x < 100; x++ )
if( isSemiPrime( x ) )
std::cout << x << " ";
return 0;
... | |
c548 | #include <iostream>
#include <string>
#include <boost/asio.hpp>
#include <boost/regex.hpp>
int main()
{
boost::asio::ip::tcp::iostream s("tycho.usno.navy.mil", "http");
if(!s)
std::cout << "Could not connect to tycho.usno.navy.mil\n";
s << "GET /cgi-bin/timer.pl HTTP/1.0\r\n"
<< "Host: tycho... | |
c549 |
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <limits>
using namespace std;
#define _(STR) STR
class Model
{
public:
static const int GOAL = 21;
static const int NUMBER_OF_PLAYERS = 2;
static const int MIN_MOVE = 1;
static const int MAX_MOVE = 3;
int bestMo... | |
c550 | #include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
#include <cstdlib>
int main( int argc , char* argv[ ] ) {
using namespace boost::gregorian ;
greg_month months[ ] = { Jan , Feb , Mar , Apr , May , Jun , Jul ,
Aug , Sep , Oct , Nov , Dec } ;
greg_year gy = atoi( argv[ 1 ] ) ;
fo... | |
c551 |
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
queue<unsigned> suspected;
vector<unsigned> primes;
bool isPrime(unsigned n)
{
if (n == 2)
{
return true;
}
if (n == 1 || n % 2 == 0)
{
return false;
}
unsigned root = sqrt(n);... | |
c552 |
#include "gmp.h"
void agm (const mpf_t in1, const mpf_t in2, mpf_t out1, mpf_t out2) {
mpf_add (out1, in1, in2);
mpf_div_ui (out1, out1, 2);
mpf_mul (out2, in1, in2);
mpf_sqrt (out2, out2);
}
int main (void) {
mpf_set_default_prec (65568);
mpf_t x0, y0, resA, resB;
mpf_init_set_ui (y0, 1);
mpf_init_set_d (... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.