_id
stringlengths
2
5
text
stringlengths
7
10.9k
title
stringclasses
1 value
c655
#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 diagonals = [...
c656
#include <string> #include <set> #include <list> #include <map> #include <iostream> struct Employee { std::string Name; std::string ID; unsigned long Salary; std::string Department; Employee(std::string _Name = "", std::string _ID = "", unsigned long _Salary = 0, std::string _Department = "") ...
c657
#include <vector> #include <iostream> #include <fstream> #include <sstream> typedef struct { int s[4]; }userI; class jit{ public: void decode( std::string& file, std::vector<userI>& ui ) { std::ifstream f( file.c_str(), std::ios_base::in ); fileBuffer = std::string( ( std::istreambuf_iterator<...
c658
#include <iostream> #include <time.h> using namespace std; const int MAX = 30; class cSort { public: void sort( int* arr, int len ) { int mi, mx, z = 0; findMinMax( arr, len, mi, mx ); int nlen = ( mx - mi ) + 1; int* temp = new int[nlen]; memset( temp, 0, nlen * sizeof( int ) ); for( int i = 0; ...
c659
#include <iostream> #include <sstream> class Vector3D { public: Vector3D(double x, double y, double z) { this->x = x; this->y = y; this->z = z; } double dot(const Vector3D& rhs) const { return x * rhs.x + y * rhs.y + z * rhs.z; } Vector3D operator-(const Vector3D& rhs) const { return Vector3D(x - rhs....
c660
#include <iostream> #include <math.h> struct PolarPoint; struct CartesianPoint { double x; double y; operator PolarPoint(); }; struct PolarPoint { double rho; double theta; operator CartesianPoint(); }; CartesianPoint::operator PolarPoint() { return PolarPoint ...
c661
#include <algorithm> #include <iostream> #include <vector> struct Point { int x, y; void rot(int n, bool rx, bool ry) { if (!ry) { if (rx) { x = (n - 1) - x; y = (n - 1) - y; } std::swap(x, y); } } }; Point fromD(int...
c662
#include <iostream> #include <fstream> bool test(const std::string &line) { unsigned int e = 0; for (char c : line) { switch(std::tolower(c)) { case 'a': return false; case 'i': return false; case 'o': return false; case 'u': return false; cas...
c663
#include <iostream> #include <cstdlib> #include <ctime> int main() { srand(time(0)); int n = 1 + (rand() % 10); int g; std::cout << "I'm thinking of a number between 1 and 10.\nTry to guess it! "; while(true) { std::cin >> g; if (g == n) break; else ...
c664
template<typename Method, typename F, typename Float> double integrate(F f, Float a, Float b, int steps, Method m) { double s = 0; double h = (b-a)/steps; for (int i = 0; i < steps; ++i) s += m(f, a + h*i, h); return h*s; } class rectangular { public: enum position_type { left, middle, right }; rect...
c665
#include <algorithm> #include <iostream> #include <iterator> int main(void) { for (int g = 1; g < 10; g++) { int v[11], n=0; generate_n(std::ostream_iterator<int>(std::cout, " "), 10, [&]{n++; return v[n]=(g<n)? v[n-g]*n : n;}); std::cout << std::endl; } return 0; }
c666
#include <time.h> #include <stdlib.h> #include <vector> #include <string> #include <iostream> class p15 { public : void play() { bool p = true; std::string a; while( p ) { createBrd(); while( !isDone() ) { drawBrd();getMove(); } drawBrd(); std:...
c667
template<class T> class matrix { public: matrix( unsigned int nSize ) : m_oData(nSize * nSize, 0), m_nSize(nSize) {} inline T& operator()(unsigned int x, unsigned int y) { return m_oData[x+m_nSize*y]; } void identity() { int nCount = 0; int nStrid...
c668
#include <vector> #include <algorithm> #include <functional> #include <iterator> #include <iostream> int main() { std::vector<int> ary; for (int i = 0; i < 10; i++) ary.push_back(i); std::vector<int> evens; std::remove_copy_if(ary.begin(), ary.end(), back_inserter(evens), std::bind2nd...
c669
#include <exception> #include <string> #include <iostream> using namespace std; namespace Roman { int ToInt(char c) { switch (c) { case 'I': return 1; case 'V': return 5; case 'X': return 10; case 'L': return 50; case 'C': return 100; case 'D': return 500; case 'M': return 1000; } ...
c670
#include <iostream> #include <fstream> #include <string> #include <iterator> int main( ) { if (std::ifstream infile("sample.txt")) { std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>()); cout << "File has " << fileData.size() << "chars\n"; ...
c671
#include <winsock2.h> #include <ws2tcpip.h> #include <iostream> int main() { WSADATA wsaData; WSAStartup( MAKEWORD( 2, 2 ), &wsaData ); addrinfo *result = NULL; addrinfo hints; ZeroMemory( &hints, sizeof( hints ) ); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP...
c672
#include <iomanip> #include <iostream> #include <sstream> #include <boost/multiprecision/cpp_int.hpp> using big_int = boost::multiprecision::cpp_int; template <typename integer> integer isqrt(integer x) { integer q = 1; while (q <= x) q <<= 2; integer r = 0; while (q > 1) { q >>= 2; ...
c673
#include <iostream> #include <set> #include <cmath> int main() { std::set<int> values; for (int a=2; a<=5; a++) for (int b=2; b<=5; b++) values.insert(std::pow(a, b)); for (int i : values) std::cout << i << " "; std::cout << std::endl; return 0; }
c674
#include <string> #include <boost/array.hpp> #include <boost/assign/list_of.hpp> #include <boost/format.hpp> #include <boost/foreach.hpp> #include <iostream> #include <math.h> using std::string; using namespace boost::assign; int get_Index(float angle) { return static_cast<int>(floor(angle / 11.25 +0.5 )) % 32 + 1;...
c675
#include <iostream> class ContinuedFraction { public: virtual const int nextTerm(){}; virtual const bool moreTerms(){}; }; class r2cf : public ContinuedFraction { private: int n1, n2; public: r2cf(const int numerator, const int denominator): n1(numerator), n2(denominator){} const int nextTerm() { const int t...
c676
#include <boost/scoped_ptr.hpp> #include <iostream> #include <queue> template<typename T> class TreeNode { public: TreeNode(const T& n, TreeNode* left = NULL, TreeNode* right = NULL) : mValue(n), mLeft(left), mRight(right) {} T getValue() const { return mValue; } TreeNode* left() const { ...
c677
#include <iostream> #include <numeric> int main() { std::cout << "The greatest common divisor of 12 and 18 is " << std::gcd(12, 18) << " !\n"; }
c678
#include "boost/filesystem.hpp" #include "boost/regex.hpp" #include <iostream> using namespace boost::filesystem; int main() { path current_dir("."); boost::regex pattern("a.*"); for (directory_iterator iter(current_dir), end; iter != end; ++iter) { boost::smatch match; std::string fn...
c679
#include <iostream> class N { private: int dVal = 0, dLen; public: N(char const* x = "0"){ int i = 0, q = 1; for (; x[i] > 0; i++); for (dLen = --i/2; i >= 0; i--) { dVal+=(x[i]-48)*q; q*=2; }} const N& operator++() { for (int i = 0;;i++) { if (dLen < i) dLen = i; swi...
c680
void step_up() { while (!step()) step_up(); }
c681
#include <algorithm> #include <iostream> template <typename BidIt, typename T> void dnf_partition(BidIt first, BidIt last, const T& low, const T& high) { for (BidIt next = first; next != last; ) { if (*next < low) { std::iter_swap(first++, next++); } else if (!(*next < high)) { ...
c682
#include <windows.h> #include <string> using namespace std; const int BMP_SIZE = 512; class myBitmap { public: myBitmap() : pen( NULL ), brush( NULL ), clr( 0 ), wid( 1 ) {} ~myBitmap() { DeleteObject( pen ); DeleteObject( brush ); DeleteDC( hdc ); DeleteObject( bmp ); } bool create( int...
c683
#include <cstdint> #include <iostream> #include <vector> std::vector<bool> prime_sieve(uint64_t limit) { std::vector<bool> sieve(limit, true); if (limit > 0) sieve[0] = false; if (limit > 1) sieve[1] = false; for (uint64_t i = 4; i < limit; i += 2) sieve[i] = false; for (uin...
c684
#include <iostream> #include <stdlib.h> class trit { public: static const trit False, Maybe, True; trit operator !() const { return static_cast<Value>(-value); } trit operator &&(const trit &b) const { return (value < b.value) ? value : b.value; } trit operator ||(const trit ...
c685
#include <string> #include <algorithm> #include <iostream> #include <set> #include <vector> auto collectSubStrings( const std::string& s, int maxSubLength ) { int l = s.length(); auto res = std::set<std::string>(); for ( int start = 0; start < l; start++ ) { int m = std::min( maxSubLength, l - ...
c686
#include <QImage> #include <cstdlib> #include <QColor> #include <iostream> int main( int argc , char *argv[ ] ) { if ( argc != 3 ) { std::cout << "Call this with imagecompare <file of image 1>" << " <file of image 2>\n" ; return 1 ; } QImage firstImage ( argv[ 1 ] ) ; QImage secondImage ( ar...
c687
#include <iostream> using namespace std; int toInt(const char c) { return c-'0'; } int confirm( const char *id) { bool is_odd_dgt = true; int s = 0; const char *cp; for(cp=id; *cp; cp++); while(cp > id) { --cp; int k = toInt(*cp); if (is_odd_dgt) { s += k; ...
c688
#include <windows.h> #include <iostream> using namespace std; class fc_dealer { public: void deal( int game ) { _gn = game; fillDeck(); shuffle(); display(); } private: void fillDeck() { int p = 0; for( int c = 0; c < 13; c++ ) for( int s = 0; s < 4; s++ ) _cards[p++] = c | s << 4;...
c689
#include <iostream> template<class T> void quibble(std::ostream& o, T i, T e) { o << "{"; if (e != i) { T n = i++; const char* more = ""; while (e != i) { o << more << *n; more = ", "; n = i++; } o << (*more?" and ":"") << *n; } o << "}"; } int main(int argc, char** argv)...
c690
#include <algorithm> #include <cassert> #include <cmath> #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...
c691
#include <iostream> bool check_isbn13(std::string isbn) { int count = 0; int sum = 0; for (auto ch : isbn) { if (ch == ' ' || ch == '-') { continue; } if (ch < '0' || ch > '9') { return false; } if (count & 1) { sum += 3 ...
c692
#include <iostream> #include <iterator> #include <vector> int main( int argc, char* argv[] ) { std::vector<bool> t; t.push_back( 0 ); size_t len = 1; std::cout << t[0] << "\n"; do { for( size_t x = 0; x < len; x++ ) t.push_back( t[x] ? 0 : 1 ); std::copy( t.begin(), t.end...
c693
#include <iostream> #include <numeric> int main() { int a[] = { 1, 3, -5 }; int b[] = { 4, -2, -1 }; std::cout << std::inner_product(a, a + sizeof(a) / sizeof(a[0]), b, 0) << std::endl; return 0; }
c694
#include <map> #include <set> template<typename Goal> class topological_sorter { protected: struct relations { std::size_t dependencies; std::set<Goal> dependents; }; std::map<Goal, relations> map; public: void add_goal(Goal const &goal) { map[goal]; } void add_dependenc...
c695
#include <numeric> #include <cctype> #include <iostream> #include <string> template<typename result_sink_t> auto sedol_checksum(std::string const& sedol, result_sink_t result_sink) { if(sedol.size() != 6) return result_sink(0, "length of sedol string != 6"); const char * valid_chars = "BCDF...
c696
#include <iostream> void leoN( int cnt, int l0 = 1, int l1 = 1, int add = 1 ) { int t; for( int i = 0; i < cnt; i++ ) { std::cout << l0 << " "; t = l0 + l1 + add; l0 = l1; l1 = t; } } int main( int argc, char* argv[] ) { std::cout << "Leonardo Numbers: "; leoN( 25 ); std::cout << "\...
c697
#include <iostream> #include <string_view> #include <boost/hana.hpp> #include <boost/hana/experimental/printable.hpp> using namespace std; namespace hana = boost::hana; constexpr auto Amb(auto constraint, auto&& ...params) { auto possibleSolutions = hana::cartesian_product(hana::tuple(params...)); auto f...
c698
#include <iostream> #include <map> #include <tuple> #include <vector> using namespace std; pair<int, int> twoSum(vector<int> numbers, int sum) { auto m = map<int, int>(); for (size_t i = 0; i < numbers.size(); ++i) { auto key = sum - numbers[i]; if (m.find(key) != m.end()) { return make_pair(m[key], i); ...
c699
#include <algorithm> #include <iostream> #include <numeric> #include <vector> template <typename T> std::vector<size_t> equilibrium(T first, T last) { typedef typename std::iterator_traits<T>::value_type value_t; value_t left = 0; value_t right = std::accumulate(first, last, value_t(0)); std::vector<...
c700
#include <iostream> #include <boost/tokenizer.hpp> #include <string> int main( ) { std::string str( "a!===b=!=c" ) , output ; typedef boost::tokenizer<boost::char_separator<char> > tokenizer ; boost::char_separator<char> separator ( "==" , "!=" ) , sep ( "!" ) ; tokenizer mytok( str , separator ) ; tok...
c701
#include <windows.h> #include <string> #include <iostream> const int BMP_SIZE = 600; class myBitmap { public: myBitmap() : pen( NULL ), brush( NULL ), clr( 0 ), wid( 1 ) {} ~myBitmap() { DeleteObject( pen ); DeleteObject( brush ); DeleteDC( hdc ); DeleteObject( bmp ); } bool create( ...
c702
#include <windows.h> #include <string> using namespace std; enum states { NONE, TREE, FIRE }; const int MAX_SIDE = 500; class myBitmap { public: myBitmap() : pen( NULL ) {} ~myBitmap() { DeleteObject( pen ); DeleteDC( hdc ); DeleteObject( bmp ); } bool create( int w, int h ) { BITMAPI...
c703
#include <iostream> #include <sstream> #include <string> const char *text = { "In olden times when wishing still helped one, there lived a king " "whose daughters were all beautiful, but the youngest was so beautiful " "that the sun itself, which has seen so much, was astonished whenever " "it shone in...
c704
#include <string> #include <vector> #include <algorithm> #include <boost/tokenizer.hpp> #include <iostream> std::vector<std::string> splitOnChar ( std::string & s , const char c ) { typedef boost::tokenizer<boost::char_separator<char>> tokenizer ; std::vector<std::string> parts ; boost::char_separator<char> s...
c705
#include <string> #include <cstdlib> #include <iostream> #include <cassert> #include <algorithm> #include <vector> #include <ctime> std::string allowed_chars = " ABCDEFGHIJKLMNOPQRSTUVWXYZ"; class selection { public: static int fitness(std::string candidate) { assert(target.length() == candid...
c706
#include <atomic> #include <chrono> #include <cmath> #include <iostream> #include <mutex> #include <thread> using namespace std::chrono_literals; class Integrator { public: using clock_type = std::chrono::high_resolution_clock; using dur_t = std::chrono::duration<double>; using func_t = double(...
c707
#include <iostream> bool valid(int n, int nuts) { for (int k = n; k != 0; k--, nuts -= 1 + nuts / n) { if (nuts % n != 1) { return false; } } return nuts != 0 && (nuts % n == 0); } int main() { int x = 0; for (int n = 2; n < 10; n++) { while (!valid(n, x)) { ...
c708
#include <iostream> #include <iomanip> #include <cmath> namespace Rosetta { template <int N> class GaussLegendreQuadrature { public: enum {eDEGREE = N}; template <typename Function> double integrate(double a, double b, Function f) { double p = (b - a) / 2...
c709
#include <cassert> #include <cmath> #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, scalar_type value) ...
c710
#include <iomanip> #include <iostream> #include <algorithm> #include <numeric> #include <string> #include <vector> typedef std::pair<int, std::vector<int> > puzzle; class nonoblock { public: void solve( std::vector<puzzle>& p ) { for( std::vector<puzzle>::iterator i = p.begin(); i != p.end(); i++ ) { ...
c711
#include <iostream> #include <vector> using Sequence = std::vector<int>; std::ostream& operator<<(std::ostream& os, const Sequence& v) { os << "[ "; for (const auto& e : v) { std::cout << e << ", "; } os << "]"; return os; } int next_in_cycle(const Sequence& s, size_t i) { return s[i % s.size()]; } ...
c712
#include <algorithm> #include <iostream> #include <string> std::string generate(int n, char left = '[', char right = ']') { std::string str(std::string(n, left) + std::string(n, right)); std::random_shuffle(str.begin(), str.end()); return str; } bool balanced(const std::string &str, char left = '[', char ...
c713
#include <iomanip> #include <iostream> bool is_prime(unsigned int n) { if (n < 2) return false; if (n % 2 == 0) return n == 2; if (n % 3 == 0) return n == 3; for (unsigned int p = 5; p * p <= n; p += 4) { if (n % p == 0) return false; p += 2; ...
c714
#include <iostream> #include <iomanip> int main( int argc, char* argv[] ) { int sol = 1; std::cout << "\t\tFIRE\t\tPOLICE\t\tSANITATION\n"; for( int f = 1; f < 8; f++ ) { for( int p = 1; p < 8; p++ ) { for( int s = 1; s < 8; s++ ) { if( f != p && f != s && p != s && !( p...
c715
#include <iostream> #include <cmath> #ifdef M_PI double const pi = M_PI; #else double const pi = 4*std::atan(1); #endif double const degree = pi/180; int main() { std::cout << "=== radians ===\n"; std::cout << "sin(pi/3) = " << std::sin(pi/3) << "\n"; std::cout << "cos(pi/3) = " << std::cos(pi/3) << "\n"; s...
c716
#include <iostream> std::ostream& operator<<(std::ostream& out, const std::string& str) { return out << str.c_str(); } std::string textBetween(const std::string& source, const std::string& beg, const std::string& end) { size_t startIndex; if (beg == "start") { startIndex = 0; } else { ...
c717
#include <algorithm> #include <iostream> #include <numeric> #include <vector> #include <list> using std::begin, std::end, std::for_each; std::list<std::vector<int>> combinations(int from, int to) { if (from > to) return {}; auto pool = std::vector<int>(to - from...
c718
#include <iostream> #include <stddef.h> #include <assert.h> using std::cout; using std::endl; class SMA { public: SMA(unsigned int period) : period(period), window(new double[period]), head(NULL), tail(NULL), total(0) { assert(period >= 1); } ~SMA() { delete[] window; } void add(double val) { i...
c719
#include <cstdint> #include <iomanip> #include <iostream> #include <sstream> class ipv4_cidr { public: ipv4_cidr() {} ipv4_cidr(std::uint32_t address, unsigned int mask_length) : address_(address), mask_length_(mask_length) {} std::uint32_t address() const { return address_; } unsi...
c720
#include <string> #include <iostream> #include <algorithm> int main() { std::string s; std::getline(std::cin, s); std::reverse(s.begin(), s.end()); std::cout << s << '\n'; }
c721
#include <windows.h> #include <iostream> #include <string> using namespace std; const int BMP_SIZE = 512, CELL_SIZE = 8; enum directions { NONE, NOR = 1, EAS = 2, SOU = 4, WES = 8 }; class myBitmap { public: myBitmap() : pen( NULL ) {} ~myBitmap() { DeleteObject( pen ); DeleteDC( hdc ); DeleteObj...
c722
#include <string> #include <algorithm> bool is_palindrome(std::string const& s) { return std::equal(s.begin(), s.end(), s.rbegin()); }
c723
#include <iostream> #include <vector> #include <chrono> #include <climits> #include <cmath> using namespace std; vector <long long> primes{ 3, 5 }; int main() { cout.imbue(locale("")); const int cutOff = 200, bigUn = 100000, chunks = 50, little = bigUn / chunks; const char tn[] = " cuban prime"; ...
c724
#include <vector> #include <iostream> int sumDigits ( int number ) { int sum = 0 ; while ( number != 0 ) { sum += number % 10 ; number /= 10 ; } return sum ; } bool isHarshad ( int number ) { return number % ( sumDigits ( number ) ) == 0 ; } int main( ) { std::vector<int> harshads ; ...
c725
#include <iostream> int main() { int i; for (i = 1; i<=10 ; i++){ std::cout << i; if (i < 10) std::cout << ", "; } return 0; }
c726
#include <iostream> #include <locale> #include <primesieve.hpp> int main() { std::cout.imbue(std::locale("")); std::cout << "The 10,001st prime is " << primesieve::nth_prime(10001) << ".\n"; }
c727
#include <algorithm> #include <cmath> #include <iostream> #include <tuple> #include <vector> int gcd(int a, int b) { int rem = 1, dividend, divisor; std::tie(divisor, dividend) = std::minmax(a, b); while (rem != 0) { rem = dividend % divisor; if (rem != 0) { dividend = divisor; ...
c728
#include <iostream> #include <cmath> #include <tuple> struct point { double x, y; }; bool operator==(const point& lhs, const point& rhs) { return std::tie(lhs.x, lhs.y) == std::tie(rhs.x, rhs.y); } enum result_category { NONE, ONE_COINCEDENT, ONE_DIAMETER, TWO, INFINITE }; using result_t = std::tuple<result_categor...
c729
#include <iostream> #include <string> #include <vector> void print_vector(const std::vector<int> &pos, const std::vector<std::string> &str) { for (size_t i = 1; i < pos.size(); ++i) printf("%s\t", str[pos[i]].c_str()); printf("\n"); } void combination_with_repetiton(int n, int k, ...
c730
#include <bitset> #include <stdio.h> #define SIZE 80 #define RULE 30 #define RULE_TEST(x) (RULE & 1 << (7 & (x))) void evolve(std::bitset<SIZE> &s) { int i; std::bitset<SIZE> t(0); t[SIZE-1] = RULE_TEST( s[0] << 2 | s[SIZE-1] << 1 | s[SIZE-2] ); t[ 0] = RULE_TEST( s[...
c731
#include <iterator> #include <utility> #include <algorithm> #include <list> #include <iostream> template<typename T> struct referring { referring(T const& t): value(t) {} template<typename Iter> bool operator()(std::pair<Iter, int> const& p) const { return *p.first == value; } T const& value; }; ...
c733
#include <boost/date_time/gregorian/gregorian.hpp> #include <iostream> int main( ) { using namespace boost::gregorian ; std::cout << "Yuletide holidays must be allowed in the following years:\n" ; for ( int i = 2008 ; i < 2121 ; i++ ) { greg_year gy = i ; date d ( gy, Dec , 25 ) ; if...
c734
#include <iostream> using namespace std; template<class T = double> class Quaternion { public: T w, x, y, z; Quaternion(const T &w, const T &x, const T &y, const T &z): w(w), x(x), y(y), z(z) {}; Quaternion(const T &x, const T &y, const T &z): w(T()), x(x), y(y), z(z) {}; Quaternion(const T &r): w(r), x(T...
c735
#include<iostream> #include<math.h> #include<stdlib.h> #include<time.h> using namespace std; int main(){ int jmax=1000; int imax=1000; double x,y; int hit; srand(time(0)); for (int j=0;j<jmax;j++){ hit=0; x=0; y=0; for(int i=0;i<imax;i++){ x=dou...
c736
#include <iostream> #include <vector> using namespace std; double horner(vector<double> v, double x) { double s = 0; for( vector<double>::const_reverse_iterator i = v.rbegin(); i != v.rend(); i++ ) s = s*x + *i; return s; } int main() { double c[] = { -19, 7, -4, 6 }; vector<double> v(c, c + sizeof(...
c737
#include <iostream> #include <windows.h> const int EL_COUNT = 77, LLEN = 11; class cocktailSort { public: void sort( int* arr, int len ) { bool notSorted = true; while( notSorted ) { notSorted = false; for( int a = 0; a < len - 1; a++ ) { if( arr[a] > arr[a + 1] ) { sSwap( arr[a], ...
c738
#include <math.h> #include <numbers> #include <stdio.h> #include <vector> std::vector<double> CalculateCoefficients(int numCoeff) { std::vector<double> c(numCoeff); double k1_factrl = 1.0; c[0] = sqrt(2.0 * std::numbers::pi); for(size_t k=1; k < numCoeff; k++) { c[k] = exp(numCoeff-k) * p...
c739
#include <iostream> #include <string> #include <vector> std::vector<std::string> makeList(std::string separator) { auto counter = 0; auto makeItem = [&](std::string item) { return std::to_string(++counter) + separator + item; }; return {makeItem("first"), makeItem("second"), makeItem("third")}; } int mai...
c740
#include <iostream> #include <iomanip> #include <vector> using uint = unsigned int; std::vector<uint> divisors(uint n) { std::vector<uint> divs; for (uint d=1; d<=n/2; d++) { if (n % d == 0) divs.push_back(d); } return divs; } uint reverse(uint n) { uint r; for (r = 0; n; n /= 10) r =...
c741
#include <iostream> #include <cmath> int main() { int n = 1; int count = 0; int sq; int cr; for (; count < 30; ++n) { sq = n * n; cr = cbrt(sq); if (cr * cr * cr != sq) { count++; std::cout << sq << '\n'; } else { std::cout << sq ...
c742
#include <iostream> int main() { std::cout << "\a"; return 0; }
c743
#include <algorithm> #include <vector> #include <set> #include <iterator> #include <iostream> #include <string> static const std::string GivenPermutations[] = { "ABCD","CABD","ACDB","DACB", "BCDA","ACBD","ADCB","CDAB", "DABC","BCAD","CADB","CDBA", "CBAD","ABDC","ADBC","BDCA", "DCBA","BACD","BADC","BDAC", "...
c744
double NthRoot(double m_nValue, double index, double guess, double pc) { double result = guess; double result_next; do { result_next = (1.0/index)*((index-1.0)*result+(m_nValue)/(pow(result,(index-1.0)))); result = result_next; pc--; }while(pc>1); ...
c745
#include <iostream> #include <boost/filesystem.hpp> using namespace boost::filesystem; int main(int argc, char *argv[]) { for (int i = 1; i < argc; ++i) { path p(argv[i]); if (exists(p) && is_directory(p)) std::cout << "'" << argv[i] << "' is" << (!is_empty(p) ? " not" : "") << " empt...
c746
#include <filesystem> #include <iostream> namespace fs = std::filesystem; int main(int argc, char* argv[]) { if(argc != 2) { std::cout << "usage: mkdir <path>\n"; return -1; } fs::path pathToCreate(argv[1]); if (fs::exists(pathToCreate)) return 0; if (fs::create_directories(pathToCreate)) return 0; ...
c747
#if _WIN32 #include <io.h> #define ISATTY _isatty #define FILENO _fileno #else #include <unistd.h> #define ISATTY isatty #define FILENO fileno #endif #include <iostream> int main() { if (ISATTY(FILENO(stdout))) { std::cout << "stdout is a tty\n"; } else { std::cout << "stdout is not a tty\n"; ...
c748
#include <algorithm> #include <string> constexpr bool is_palindrome(std::string_view s) { return std::equal(s.begin(), s.begin()+s.length()/2, s.rbegin()); }
c749
#include <iostream> const int WIDTH = 81; const int HEIGHT = 5; char lines[WIDTH*HEIGHT]; void cantor(int start, int len, int index) { int seg = len / 3; if (seg == 0) return; for (int i = index; i < HEIGHT; i++) { for (int j = start + seg; j < start + seg * 2; j++) { int pos = i * WIDTH + j; lines[pos] =...
c750
#if !defined(__cplusplus) || __cplusplus < 201103L #pragma error("The following code requires at least C++11.") #else #endif
c751
bool isOdd(int x) { return x % 2; } bool isEven(int x) { return !(x % 2); }
c752
#include <vector> #include <utility> #include <algorithm> #include <iostream> #include <sstream> #include <string> #include <cmath> bool isVampireNumber( long number, std::vector<std::pair<long, long> > & solution ) { std::ostringstream numberstream ; numberstream << number ; std::string numberstring( number...
c753
#include <iostream> #include <complex> int main() { std::cout << std::exp(std::complex<double>(0.0, M_PI)) + 1.0 << std::endl; return 0; }
c754
#include <array> #include <cstdlib> #include <ctime> #include <iostream> #include <string> int main() { constexpr std::array<const char*, 20> answers = { "It is certain.", "It is decidedly so.", "Without a doubt.", "Yes - definitely.", "You may rely on it.", "As I se...
c755
#include <iostream> enum class Mode { ENCRYPT, DECRYPT, }; const std::string L_ALPHABET = "HXUCZVAMDSLKPEFJRIGTWOBNYQ"; const std::string R_ALPHABET = "PTLNBQDEOYSFAVZKGJRIHWXUMC"; std::string exec(std::string text, Mode mode, bool showSteps = false) { auto left = L_ALPHABET; auto right = R_ALPHABET;...