_id stringlengths 2 5 | text stringlengths 7 10.9k | title stringclasses 1
value |
|---|---|---|
c860 | #include <iomanip>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
void calcMDR( int n, int c, int& a, int& b )
{
int m = n % 10; n /= 10;
while( n )
{
m *= ( n % 10 );
n /= 10;
}
if( m >= 10 ) calcMDR( m, ++c, a, b );
else { a = m; b = c; }
}
void table()
{
map... | |
c861 | #include<graphics.h>
#include<iostream>
int main()
{
int k;
initwindow(1500,810,"Rosetta Cuboid");
do{
std::cout<<"Enter ratio of sides ( 0 or -ve to exit) : ";
std::cin>>k;
if(k>0){
bar3d(100, 100, 100 + 2*k, 100 + 4*k, 3*k, 1);
}
}while(k>0)... | |
c862 | #include <cstdlib>
#include <fstream>
#include <iostream>
bool is_abc_word(const std::string& word) {
bool a = false;
bool b = false;
for (char ch : word) {
switch (ch) {
case 'a':
if (!a)
a = true;
break;
case 'b':
if (!b) {
... | |
c863 | #include <Windows.h>
int main()
{
bool showCursor = false;
HANDLE std_out = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursorInfo;
GetConsoleCursorInfo(out, &cursorInfo);
cursorInfo.bVisible = showCursor;
SetConsoleCursorInfo(out, &cursorInfo); ... | |
c864 | #include <string>
#include <numeric>
int main() {
std::string lower(26,' ');
std::iota(lower.begin(), lower.end(), 'a');
}
| |
c865 | #include <algorithm>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <string>
#include <gmpxx.h>
bool is_probably_prime(const mpz_class& n) {
return mpz_probab_prime_p(n.get_mpz_t(), 3) != 0;
}
bool is_prime(int n) {
if (n < 2)
return false;
if (n % 2 == 0)
return n == 2... | |
c866 | #include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iterator>
#include <cstdlib>
double rpn(const std::string &expr){
std::istringstream iss(expr);
std::vector<double> stack;
std::cout << "Input\tOperation\tStack after" << std::endl;
std::s... | |
c867 |
#include <iostream>
#include <QDomDocument>
#include <QObject>
int main() {
QDomDocument doc;
doc.setContent(
QObject::tr(
"<Students>\n"
"<Student Name=\"April\" Gender=\"F\" DateOfBirth=\"1989-01-02\" />\n"
"<Student Name=\"Bob\" Gender=\"M\" DateOfBirth=\"1990-03-04\... | |
c868 | #include <cstdlib>
#include <algorithm>
#include <iterator>
template<typename RandomAccessIterator>
void knuthShuffle(RandomAccessIterator begin, RandomAccessIterator end) {
for(unsigned int n = end - begin - 1; n >= 1; --n) {
unsigned int k = rand() % (n + 1);
if(k != n) {
std::iter_swap(begin + k, be... | |
c869 | #include <set>
#include <iostream>
#include <iterator>
#include <algorithm>
namespace set_display {
template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& set)
{
os << '[';
if (!set.empty()) {
std::copy(set.begin(), --set.end(), std::ostream_iterator<T>(os, ", "));
os ... | |
c870 | #include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
using triple = std::tuple<int, int, int>;
void print_triple(std::ostream& out, const triple& t) {
out << '(' << std::get<0>(t) << ',' << std::get<1>(t) << ',' << std::get<2>(t) << ')';
}
void print_vector(std::ostream& out, const std::vector... | |
c871 | #include<iostream>
#include<unistd.h>
int main()
{
pid_t pid = fork();
if (pid == 0)
{
std::cout << "This is the new process\n";
}
else if (pid > 0)
{
std::cout << "This is the original process\n";
}
else
{
std::cerr << "ERROR: Something went wrong\n";
}
return 0;
}
| |
c872 | #include <iostream>
double f(double x)
{
return (x*x*x - 3*x*x + 2*x);
}
int main()
{
double step = 0.001;
double start = -1;
double stop = 3;
double value = f(start);
double sign = (value > 0);
if ( 0 == value )
std::cout << "Root found at " << start << std::endl;
for( double x = start + step;
x <... | |
c873 | template<int N>
struct Half
{
enum { Result = N >> 1 };
};
template<int N>
struct Double
{
enum { Result = N << 1 };
};
template<int N>
struct IsEven
{
static const bool Result = (N ... | |
c874 | #include <iostream>
#include <cmath>
#include <utility>
#include <vector>
#include <stdexcept>
using namespace std;
typedef std::pair<double, double> Point;
double PerpendicularDistance(const Point &pt, const Point &lineStart, const Point &lineEnd)
{
double dx = lineEnd.first - lineStart.first;
double dy = lineEnd.... | |
c875 | template<class InputIterator, class InputIterator2>
void writedat(const char* filename,
InputIterator xbegin, InputIterator xend,
InputIterator2 ybegin, InputIterator2 yend,
int xprecision=3, int yprecision=5)
{
std::ofstream f;
f.exceptions(std::ofstream::failbit | std::of... | |
c876 | #include <iostream>
float epsilon() {
float eps = 1.0f;
while (1.0f + eps != 1.0f) eps /= 2.0f;
return eps;
}
float kahanSum(std::initializer_list<float> nums) {
float sum = 0.0f;
float c = 0.0f;
for (auto num : nums) {
float y = num - c;
float t = sum + y;
c = (t - sum... | |
c877 | template<typename T> void swap(T& left, T& right)
{
T tmp(left);
left = right;
right = tmp;
}
| |
c878 | #include <iomanip>
#include <iostream>
#include <list>
using namespace std;
void sieve(int limit, list<int> &primes)
{
bool *c = new bool[limit + 1];
for (int i = 0; i <= limit; i++)
c[i] = false;
int p = 3, n = 0;
int p2 = p * p;
while (p2 <= limit)
{
for (int i = p2; i <= limit; i += 2 * p)
... | |
c879 |
#include <iostream>
#include <cmath>
#include <utility>
template<class P_> P_ IncFirst(const P_& src) {return P_(src.first + 1, src.second);}
std::pair<int, int> DigitalRoot(unsigned long long digits, int base = 10)
{
int x = SumDigits(digits, base);
return x < base ? std::make_pair(1, x) : IncFirst(Digi... | |
c880 | void number_reversal_game()
{
cout << "Number Reversal Game. Type a number to flip the first n numbers.";
cout << "You win by sorting the numbers in ascending order.";
cout << "Anything besides numbers are ignored.\n";
cout << "\t |1__2__3__4__5__6__7__8__9|\n";
int list[9] = {1,2,3,4,5,6,7,8,9};
do
... | |
c881 | namespace rosettacode
{
template<typename T> class queue
{
public:
queue();
~queue();
void push(T const& t);
T pop();
bool empty();
private:
void drop();
struct node;
node* head;
node* tail;
};
template<typename T> struct queue<T>::node
{
T data;
node* next;
... | |
c882 | #include <fstream>
#include <iostream>
std::string execute(const std::string& command) {
system((command + " > temp.txt").c_str());
std::ifstream ifs("temp.txt");
std::string ret{ std::istreambuf_iterator<char>(ifs), std::istreambuf_iterator<char>() };
ifs.close();
if (std::remove("temp.txt") != ... | |
c883 | #include <iostream>
#include <vector>
#include <algorithm>
#include <stdexcept>
#include <memory>
#include <sys/time.h>
using std::cout;
using std::endl;
class StopTimer
{
public:
StopTimer(): begin_(getUsec()) {}
unsigned long long getTime() const { return getUsec() - begin_; }
private:
static unsigned l... | |
c884 | #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <time.h>
using namespace std;
const unsigned int LEN = 4;
class CowsAndBulls_Player
{
public:
CowsAndBulls_Player() { fillPool(); }
void play() { secret = createSecret(); guess(); }
private:
void... | |
c885 | #include <iostream>
#include <vector>
using entry = std::pair<int, const char*>;
void print(const std::vector<entry>& entries, std::ostream& out = std::cout)
{
bool first = true;
for(const auto& e: entries) {
if(!first) out << ", ";
first = false;
out << e.first << " " << e.second;
... | |
c886 | #include <iostream>
#include <algorithm>
#include <vector>
int pShuffle( int t ) {
std::vector<int> v, o, r;
for( int x = 0; x < t; x++ ) {
o.push_back( x + 1 );
}
r = o;
int t2 = t / 2 - 1, c = 1;
while( true ) {
v = r;
r.clear();
for( int x = t2; x > -1; x-... | |
c887 | #include <algorithm>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
void SimpleConsolidate(vector<unordered_set<char>>& sets)
{
for(auto last = sets.rbegin(); last != sets.rend(); ++last)
for(auto other = last + 1; other != sets.rend(); +... | |
c888 | #include <concepts>
#include <iostream>
void PrintMatrix(std::predicate<int, int, int> auto f, int size)
{
for(int y = 0; y < size; y++)
{
for(int x = 0; x < size; x++)
{
std::cout << " " << f(x, y, size);
}
std::cout << "\n";
}
std::cout << "\n";
}
int main()
{
auto fourSides = [... | |
c889 | #include <windows.h>
#include <string>
#include <math.h>
using namespace std;
const int BMP_SIZE = 300, MY_TIMER = 987654, CENTER = BMP_SIZE >> 1, SEC_LEN = CENTER - 20,
MIN_LEN = SEC_LEN - 20, HOUR_LEN = MIN_LEN - 20;
const float PI = 3.1415926536f;
class vector2
{
public:
vector2() { x = y = 0; }
... | |
c890 | #include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
class cupboard {
public:
cupboard() {
for (int i = 0; i < 100; i++)
drawers[i] = i;
random_shuffle(drawers, drawers + 100);
}
bool playRandom();
bool playOptimal();
private:
int dra... | |
c891 | #include <cstdlib>
#include <cstdio>
int main()
{
puts(getenv("HOME"));
return 0;
}
| |
c892 | #include <iterator>
#include <algorithm>
#include <functional>
template<typename RandomAccessIterator, typename Order>
void mergesort(RandomAccessIterator first, RandomAccessIterator last, Order order)
{
if (last - first > 1)
{
RandomAccessIterator middle = first + (last - first) / 2;
mergesort(first, m... | |
c893 | struct Point
{
int x;
int y;
};
| |
c894 | #include <fstream>
#include <iostream>
#include <iterator>
#include <vector>
class subleq {
public:
void load_and_run( std::string file ) {
std::ifstream f( file.c_str(), std::ios_base::in );
std::istream_iterator<int> i_v, i_f( f );
std::copy( i_f, i_v, std::back_inserter( memory ) );
... | |
c895 | #include <iostream>
#include <fstream>
#include <string>
#include <vector>
std::ostream& operator<<(std::ostream& out, const std::string s) {
return out << s.c_str();
}
struct gecos_t {
std::string fullname, office, extension, homephone, email;
friend std::ostream& operator<<(std::ostream&, const gecos_t... | |
c896 | #include <chrono>
#include <iostream>
#include <format>
#include <semaphore>
#include <thread>
using namespace std::literals;
void Worker(std::counting_semaphore<>& semaphore, int id)
{
semaphore.acquire();
std::cout << std::format("Thread {} has a semaphore & is now working.\n", id);
std::this_thread:... | |
c897 |
MyClass::method(someParameter);
myInstance.method(someParameter);
MyPointer->method(someParameter);
| |
c898 | #include <iomanip>
#include <iostream>
#include <sstream>
using namespace std;
enum CipherMode {ENCRYPT, DECRYPT};
uint32_t randRsl[256];
uint32_t randCnt;
uint32_t mm[256];
uint32_t aa = 0, bb = 0, cc = 0;
void isaac()
{
++cc;
bb += cc;
for (uint32_t i = 0; i < 256; ++i)
{
uin... | |
c899 | #include <concepts>
#include <iostream>
void PrintMatrix(std::predicate<int, int, int> auto f, int size)
{
for(int y = 0; y < size; y++)
{
for(int x = 0; x < size; x++)
{
std::cout << " " << f(x, y, size);
}
std::cout << "\n";
}
std::cout << "\n";
}
int main()
{
auto mosaic = [](i... | |
c900 | #include <string>
#include <iostream>
#include <algorithm>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/casts.hpp>
#include <ctime>
#include <cstdlib>
using namespace boost::lambda ;
struct MyRandomizer {
char operator( )( ) {
return static_cast<char>( rand( ) % 256 ) ;
}
} ;
std::string dele... | |
c901 | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
class Vector {
private:
double px, py, pz;
public:
Vector() : px(0.0), py(0.0), pz(0.0) {
}
Vector(double x, double y, double z) : px(x), py(y), pz(z) {
}
doub... | |
c904 | #include <algorithm>
#include <iostream>
#include <vector>
class SubMatrix {
const std::vector<std::vector<double>> *source;
std::vector<double> replaceColumn;
const SubMatrix *prev;
size_t sz;
int colIndex = -1;
public:
SubMatrix(const std::vector<std::vector<double>> &src, const std::vector<... | |
c905 | #include <ctime>
#include <string>
#include <iostream>
#include <algorithm>
class cycle{
public:
template <class T>
void cy( T* a, int len ) {
int i, j;
show( "original: ", a, len );
std::srand( unsigned( time( 0 ) ) );
for( int i = len - 1; i > 0; i-- ) {
do {
... | |
c906 | #include <iostream>
#include <ostream>
template<typename T>
T f(const T& x) {
return (T) pow(x, 100) + x + 1;
}
class ModularInteger {
private:
int value;
int modulus;
void validateOp(const ModularInteger& rhs) const {
if (modulus != rhs.modulus) {
throw std::runtime_error("Left-h... | |
c907 | #include <iostream>
#include <string>
#include <boost/date_time/gregorian/gregorian.hpp>
bool is_palindrome(const std::string& str) {
for (size_t i = 0, j = str.size(); i + 1 < j; ++i, --j) {
if (str[i] != str[j - 1])
return false;
}
return true;
}
int main() {
using boost::gregori... | |
c908 | #include <iostream>
class Acc
{
public:
Acc(int init)
: _type(intType)
, _intVal(init)
{}
Acc(float init)
: _type(floatType)
, _floatVal(init)
{}
int operator()(int x)
{
if( _type == intType )
{
_intVal += x;
return _intV... | |
c909 | #include <string>
#include <iostream>
#include <cstdlib>
#include <math.h>
#include <chrono>
#include <iomanip>
using namespace std;
const int maxBase = 16;
int base, bmo, tc;
const string chars = "0123456789ABCDEF";
unsigned long long full;
string toStr(const unsigned long long ull) {
unsigned long long u =... | |
c910 | #include <algorithm>
#include <iostream>
#include <numeric>
#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);
if (i !... | |
c911 | #include <iostream>
using namespace std;
class mRND
{
public:
void seed( unsigned int s ) { _seed = s; }
protected:
mRND() : _seed( 0 ), _a( 0 ), _c( 0 ), _m( 2147483648 ) {}
int rnd() { return( _seed = ( _a * _seed + _c ) % _m ); }
int _a, _c;
unsigned int _m, _seed;
};
class MS_RND : public... | |
c912 | #include <iostream>
#include <iomanip>
int main()
{
std::cout << std::setfill('0') << std::setw(9) << std::fixed << std::setprecision(3) << 7.125 << std::endl;
return 0;
}
| |
c913 | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>
template <typename T>
size_t indexOf(const std::vector<T> &v, const T &k) {
auto it = std::find(v.cbegin(), v.cend(), k);
if (it != v.cend()) {
return it - v.cbegin();
}
return -1;
}... | |
c914 | #include <iostream>
#include <iomanip>
using namespace std;
class converter
{
public:
converter() : KTC( 273.15f ), KTDel( 3.0f / 2.0f ), KTF( 9.0f / 5.0f ), KTNew( 33.0f / 100.0f ),
KTRank( 9.0f / 5.0f ), KTRe( 4.0f / 5.0f ), KTRom( 21.0f / 40.0f ) {}
void convert( float kelvin )
{
float... | |
c916 | #include <iomanip>
#include <iostream>
using namespace std;
string replaceFirst(string &s, const string &target, const string &replace) {
auto pos = s.find(target);
if (pos == string::npos) return s;
return s.replace(pos, target.length(), replace);
}
int main() {
string x = "hello world";
... | |
c917 | #include <string>
#include <iostream>
using namespace std;
string Suffix(int num)
{
switch (num % 10)
{
case 1 : if(num % 100 != 11) return "st";
break;
case 2 : if(num % 100 != 12) return "nd";
break;
case 3 : if(num % 100 != 13) return "rd";
}
return "t... | |
c918 | #include <algorithm>
#include <cstddef>
#include <cassert>
template<typename MatrixType> struct matrix_traits
{
typedef typename MatrixType::index_type index_type;
typedef typename MatrixType::value_type value_type;
static index_type min_row(MatrixType const& A)
{ return A.min_row()... | |
c919 | #include <algorithm>
#include <chrono>
#include <iostream>
#include <vector>
int ulam(int n) {
std::vector<int> ulams{1, 2};
std::vector<int> sieve{1, 1};
for (int u = 2; ulams.size() < n; ) {
sieve.resize(u + ulams[ulams.size() - 2], 0);
for (int i = 0; i < ulams.size() - 1; ++i)
... | |
c920 | #include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
class StraddlingCheckerboard
{
map<char, string> table;
char first[10], second[10], third[10];
int rowU, rowV;
public:
StraddlingCheckerboard(const string &alphabet, int u, int v)
{
rowU = min(u, v);
rowV... | |
c921 | #include <functional>
#include <cmath>
#include <iostream>
template <class Fun1, class Fun2>
class compose_functor :
public std::unary_function<typename Fun2::argument_type,
typename Fun1::result_type>
{
protected:
Fun1 f;
Fun2 g;
public:
compose_functor(const Fun1& _f, const Fun... | |
c922 | #include<cstdio>
int main(){char n[]=R"(#include<cstdio>
int main(){char n[]=R"(%s%c";printf(n,n,41);})";printf(n,n,41);}
| |
c923 | #include <iostream>
#include <optional>
#include <vector>
#include <string>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int integer;
struct fraction {
fraction(const integer& n, const integer& d) : numerator(n), denominator(d) {}
integer numerator;
int... | |
c924 | #include "boost/filesystem.hpp"
#include <string>
#include <iostream>
void testfile(std::string name)
{
boost::filesystem::path file(name);
if (exists(file))
{
if (is_directory(file))
std::cout << name << " is a directory.\n";
else
std::cout << name << " is a non-directory file.\n";
}
els... | |
c925 | #include <iostream>
#include <queue>
#include <map>
#include <climits>
#include <iterator>
#include <algorithm>
const int UniqueSymbols = 1 << CHAR_BIT;
const char* SampleString = "this is an example for huffman encoding";
typedef std::vector<bool> HuffCode;
typedef std::map<char, HuffCode> HuffCodeMap;
class INode... | |
c926 |
#include <string>
#include <chrono>
#include <cmath>
#include <locale>
using namespace std;
using namespace chrono;
unsigned int js(int l, int n) {
unsigned int res = 0, f = 1;
double lf = log(2) / log(10), ip;
for (int i = l; i > 10; i /= 10) f *= 10;
while (n > 0)
if ((int)(f * pow(10, modf(++res * ... | |
c927 | #include <iostream>
#include <cstdlib>
if (object == 0) {
std::cout << "object is null";
}
| |
c928 | #include <iostream>
#include "xtensor/xarray.hpp"
#include "xtensor/xio.hpp"
#include "xtensor-io/ximage.hpp"
xt::xarray<int> init_grid (unsigned long x_dim, unsigned long y_dim)
{
xt::xarray<int>::shape_type shape = { x_dim, y_dim };
xt::xarray<int> grid(shape);
grid(x_dim/2, y_dim/2) = 64000;
r... | |
c929 | template <typename T>
struct Node
{
Node* next;
Node* prev;
T data;
};
| |
c930 | #include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>
#include <tuple>
typedef std::tuple<int, int> point;
std::ostream& print(std::ostream& os, const point& p) {
return os << "(" << std::get<0>(p) << ", " << std::get<1>(p) << ")";
}
std::ostream& print(std::ostream& os, const std::vector... | |
c931 | #include <iostream>
#include <string>
#include <fstream>
class cipher {
public:
bool work( std::string e, std::string f, std::string k ) {
if( e.length() < 1 ) return false;
fileBuffer = readFile( f );
if( "" == fileBuffer ) return false;
keyBuffer = readFile( k );
if( "" ==... | |
c932 | #include <algorithm>
#include <iostream>
#include <sstream>
#include <gmpxx.h>
using integer = mpz_class;
std::string to_string(const integer& n) {
std::ostringstream out;
out << n;
return out.str();
}
integer next_highest(const integer& n) {
std::string str(to_string(n));
if (!std::next_permuta... | |
c933 | #include <map>
#include <set>
bool happy(int number) {
static std::map<int, bool> cache;
std::set<int> cycle;
while (number != 1 && !cycle.count(number)) {
if (cache.count(number)) {
number = cache[number] ? 1 : 0;
break;
}
cycle.insert(number);
int newnumber = 0;
while (number >... | |
c934 | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <gmpxx.h>
using integer = mpz_class;
class unsigned_stirling1 {
public:
integer get(int n, int k);
private:
std::map<std::pair<int, int>, integer> cache_;
};
integer unsigned_stirling1::get(int n, int k) {
if (k == 0)
... | |
c935 | #include <string>
#include <iostream>
#include <iterator>
#include <fstream>
#include <boost/regex.hpp>
int main( ) {
std::ifstream codeFile( "samplecode.txt" ) ;
if ( codeFile ) {
boost::regex commentre( "/\\*.*?\\*/" ) ;
std::string my_erase( "" ) ;
std::string stripped ;
... | |
c937 | #include <cassert>
int main()
{
int a;
assert(a == 42);
}
| |
c938 | #include <iomanip>
#include <iostream>
int factorial_mod(int n, int p) {
int f = 1;
for (; n > 0 && f != 0; --n)
f = (f * n) % p;
return f;
}
bool is_prime(int p) {
return p > 1 && factorial_mod(p - 1, p) == p - 1;
}
int main() {
std::cout << " n | prime?\n------------\n";
std::cout ... | |
c939 | #include <iostream>
#include <random>
#include <vector>
int main( ) {
std::vector<int> numbers { 11 , 88 , -5 , 13 , 4 , 121 , 77 , 2 } ;
std::random_device seed ;
std::mt19937 engine( seed( ) ) ;
std::uniform_int_distribution<int> choose( 0 , numbers.size( ) - 1 ) ;
std::cout << "random element... | |
c940 | #include <QByteArray>
#include <iostream>
int main( ) {
QByteArray text ( "http:
QByteArray encoded( text.toPercentEncoding( ) ) ;
std::cout << encoded.data( ) << '\n' ;
return 0 ;
}
| |
c941 | #include <gmpxx.h>
#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;
... | |
c942 | #include <iomanip>
#include <iostream>
#include <map>
#include <sstream>
bool isHumble(int i) {
if (i <= 1) return true;
if (i % 2 == 0) return isHumble(i / 2);
if (i % 3 == 0) return isHumble(i / 3);
if (i % 5 == 0) return isHumble(i / 5);
if (i % 7 == 0) return isHumble(i / 7);
return false;
... | |
c943 | #include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
class ulamSpiral {
public:
void create( unsigned n, unsigned startWith = 1 ) {
_lst.clear();
if( !( n & 1 ) ) n++;
_mx = n;
unsigned v = n * n;
_wd = static_cast<unsigned>( log10( sta... | |
c944 | #include <iostream>
int main()
{
std::cout << static_cast<char>(163);
return 0;
}
| |
c945 | using System;
class Program {
static int l;
static int[] gp(int n) {
var c = new bool[n]; var r = new int[(int)(1.28 * n)];
l = 0; r[l++] = 2; r[l++] = 3; int j, d, lim = (int)Math.Sqrt(n);
for (int i = 9; i < n; i += 6) c[i] = true;
for (j = 5, d = 4; j < lim; j += (d = 6 - ... | |
c0 | #include <array>
#include <iostream>
#include <vector>
#include <boost/circular_buffer.hpp>
#include "prime_sieve.hpp"
int main() {
using std::cout;
using std::vector;
using boost::circular_buffer;
using group_buffer = circular_buffer<vector<int>>;
const int max = 1000035;
const int max_group_... | |
c1 | #include <vector>
#include <iterator>
#include <algorithm>
template<typename InputIterator, typename OutputIterator>
OutputIterator forward_difference(InputIterator first, InputIterator last,
OutputIterator dest)
{
if (first == last)
return dest;
typedef typename... | |
c2 | #include <cmath>
bool is_prime(unsigned int n)
{
if (n <= 1)
return false;
if (n == 2)
return true;
for (unsigned int i = 2; i <= sqrt(n); ++i)
if (n % i == 0)
return false;
return true;
}
| |
c3 | double Factorial(double nValue)
{
double result = nValue;
double result_next;
double pc = nValue;
do
{
result_next = result*(pc-1);
result = result_next;
pc--;
}while(pc>2);
nValue = result;
return nValue;
}
double binomialC... | |
c4 | int a[5];
a[0] = 1;
int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 };
#include <string>
std::string strings[4];
| |
c5 | #include <iostream>
#include <forward_list>
int main()
{
std::forward_list<int> list{1, 2, 3, 4, 5};
for (int e : list)
std::cout << e << std::endl;
}
| |
c6 | #include <fstream>
#include <cstdio>
int main() {
constexpr auto dimx = 800u, dimy = 800u;
using namespace std;
ofstream ofs("first.ppm", ios_base::out | ios_base::binary);
ofs << "P6" << endl << dimx << ' ' << dimy << endl << "255" << endl;
for (auto j = 0u; j < dimy; ++j)
for (auto i = ... | |
c7 | #include <cstdio>
#include <direct.h>
int main() {
remove( "input.txt" );
remove( "/input.txt" );
_rmdir( "docs" );
_rmdir( "/docs" );
return 0;
}
| |
c9 | #include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <iterator>
using namespace std;
class myTuple
{
public:
void set( int a, int b, string c ) { t.first.first = a; t.first.second = b; t.second = c; }
bool operator == ( pair<int, int> p ) { return p.first == t.first.first && p.... | |
c10 | #include <time.h>
#include <iostream>
#include <string>
typedef unsigned char byte;
using namespace std;
class flip
{
public:
flip() { field = 0; target = 0; }
void play( int w, int h ) { wid = w; hei = h; createField(); gameLoop(); }
private:
void gameLoop()
{
int moves = 0;
while( !solved() )
{
... | |
c11 | #include <iostream>
#include <iomanip>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/math/constants/constants.hpp>
typedef boost::multiprecision::cpp_dec_float_50 decfloat;
int main()
{
const decfloat ln_two = boost::math::constants::ln_two<decfloat>();
decfloat numerator = 1, denominator =... | |
c12 | #include <random>
#include <random>
#include <vector>
#include <iostream>
#define MAX_N 20
#define TIMES 1000000
static std::random_device rd;
static std::mt19937 gen(rd());
static std::uniform_int_distribution<> dis;
int randint(int n) {
int r, rmax = RAND_MAX / n * n;
dis=std::uniform_int_distribution<... | |
c13 | #include <string>
#include <iostream>
int main( ) {
std::string original( "Mary had a X lamb." ) , toBeReplaced( "X" ) ,
replacement ( "little" ) ;
std::string newString = original.replace( original.find( "X" ) ,
toBeReplaced.length( ) , replacement ) ;
std::cout << "String after replacement: " << new... | |
c14 | #include <iostream>
#include <vector>
#include <stack>
#include <iterator>
#include <algorithm>
#include <cassert>
template <class E>
struct pile_less {
bool operator()(const std::stack<E> &pile1, const std::stack<E> &pile2) const {
return pile1.top() < pile2.top();
}
};
template <class E>
struct pile_greater... | |
c15 | #include <array>
#include <iomanip>
#include <iostream>
#include <random>
#include <string>
class sequence_generator {
public:
sequence_generator();
std::string generate_sequence(size_t length);
void mutate_sequence(std::string&);
static void print_sequence(std::ostream&, const std::string&);
enum ... | |
c16 | #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;
... | |
c17 | #include <iostream>
#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 (it != end) {
os << ", " << *i... | |
c18 | #include <chrono>
#include <iostream>
#include <vector>
#include <gmpxx.h>
using big_int = mpz_class;
big_int partitions(int n) {
std::vector<big_int> p(n + 1);
p[0] = 1;
for (int i = 1; i <= n; ++i) {
for (int k = 1;; ++k) {
int j = (k * (3*k - 1))/2;
if (j > i)
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.