_id
stringlengths
2
5
text
stringlengths
7
10.9k
title
stringclasses
1 value
c553
for (int i = 1; i < 10; i += 2) std::cout << i << std::endl;
c554
#include <iostream> #include <cmath> #include <chrono> using namespace std; using namespace chrono; int main() { auto st = high_resolution_clock::now(); const uint i5 = 100000, i4 = 10000, i3 = 1000, i2 = 100, i1 = 10; uint p4[] = { 0, 1, 32, 243 }, nums[10], p5[10], t = 0, m5, m4, m3, m2, m1, m0; m5 = m4 ...
c555
#ifndef CLICKCOUNTER_H #define CLICKCOUNTER_H #include <QWidget> class QLabel ; class QPushButton ; class QVBoxLayout ; class Counter : public QWidget { Q_OBJECT public : Counter( QWidget * parent = 0 ) ; private : int number ; QLabel *countLabel ; QPushButton *clicker ; QVBoxLayout *myLayout ; pri...
c556
#include <iostream> #include <fstream> std::ios::off_type getFileSize(const char *filename) { std::ifstream f(filename); std::ios::pos_type begin = f.tellg(); f.seekg(0, std::ios::end); std::ios::pos_type end = f.tellg(); return end - begin; } int main() { std::cout << getFileSize("input.txt") << std::end...
c557
#include <iostream> #include "prime_sieve.hpp" bool is_left_truncatable(const prime_sieve& sieve, int p) { for (int n = 10, q = p; p > n; n *= 10) { if (!sieve.is_prime(p % n) || q == p % n) return false; q = p % n; } return true; } bool is_right_truncatable(const prime_sieve& ...
c558
#include <iostream> #include <thread> #include <chrono> int main() { unsigned long microseconds; std::cin >> microseconds; std::cout << "Sleeping..." << std::endl; std::this_thread::sleep_for(std::chrono::microseconds(microseconds)); std::cout << "Awake!\n"; }
c559
#include <iostream> int main() { bool is_open[100] = { false }; for (int pass = 0; pass < 100; ++pass) for (int door = pass; door < 100; door += pass+1) is_open[door] = !is_open[door]; for (int door = 0; door < 100; ++door) std::cout << "door #" << door+1 << (is_open[door]? " is open." : " ...
c560
#include <iomanip> #include <iostream> #include <vector> #define _USE_MATH_DEFINES #include <math.h> struct Time { int hour, minute, second; friend std::ostream &operator<<(std::ostream &, const Time &); }; std::ostream &operator<<(std::ostream &os, const Time &t) { return os << std::setfill('0') ...
c561
#include <future> #include <iostream> #include <fstream> #include <mutex> #include <queue> #include <string> #include <thread> struct lock_queue { std::queue<std::string> q; std::mutex mutex; }; void reader(std::string filename, std::future<size_t> lines, lock_queue& out) { std::string line; std::ifst...
c562
#include <iostream> #include <vector> typedef std::vector<std::vector<int>> vv; vv pascal_upper(int n) { vv matrix(n); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i > j) matrix[i].push_back(0); else if (i == j || i == 0) matrix[i].push_back(1); ...
c563
#include <iostream> int main() { std::cerr << "Goodbye, World!\n"; }
c564
#include <algorithm> #include <iostream> #include <iterator> #include <locale> #include <vector> #include "prime_sieve.hpp" const int limit1 = 1000000; const int limit2 = 10000000; class prime_info { public: explicit prime_info(int max) : max_print(max) {} void add_prime(int prime); void print(std::ostrea...
c565
#include <iomanip> #include <iostream> #include <fstream> #include <map> #include <sstream> #include <string> #include <vector> std::vector<std::string> split(const std::string& str, char delimiter) { std::vector<std::string> tokens; std::string token; std::istringstream tokenStream(str); while (std::g...
c566
#include<iostream> #include<csignal> #include<cstdlib> using namespace std; void fpe_handler(int signal) { cerr << "Floating Point Exception: division by zero" << endl; exit(signal); } int main() { signal(SIGFPE, fpe_handler); int a = 1; int b = 0; cout << a/b << endl; return 0; }...
c567
#include <algorithm> #include <string> std::all_of( ++(strings.begin()), strings.end(), [&](std::string a){ return a == strings.front(); } ) std::is_sorted( strings.begin(), strings.end(), [](std::string a, std::string b){ return !(b < a); }) )
c568
#include <algorithm> #include <fstream> #include <iostream> #include <iterator> #include <string> #include <vector> bool ordered(const std::string &word) { return std::is_sorted(word.begin(), word.end()); } int main() { std::ifstream infile("unixdict.txt"); if (!infile) { std::cerr << "Can't open...
c569
#include <iostream> #include <chrono> int main() { int fizz = 0, buzz = 0, fizzbuzz = 0; bool isFizz = false; auto startTime = std::chrono::high_resolution_clock::now(); for (unsigned int i = 1; i <= 4000000000; i++) { isFizz = false; if (i % 3 == 0) { isFizz = true; fizz++; } if (i % 5 == 0) {...
c570
#include <list> #include <boost/any.hpp> typedef std::list<boost::any> anylist; void flatten(std::list<boost::any>& list) { typedef anylist::iterator iterator; iterator current = list.begin(); while (current != list.end()) { if (current->type() == typeid(anylist)) { iterator next = current; ...
c571
struct MyException { };
c572
#include <QtSql> #include <iostream> int main(int argc, char *argv[]) { if (argc != 4) { std::cerr << "Usage: " << argv[0] << " data-source user password\n"; return 1; } QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); db.setDatabaseName(argv[1]); if (!db.open(argv[2], argv[...
c573
#include <iostream> #include <vector> constexpr unsigned int LIMIT = 6000; std::vector<bool> primes(unsigned int limit) { std::vector<bool> p(limit + 1, true); unsigned int root = std::sqrt(limit); p[0] = false; p[1] = false; for (size_t i = 2; i <= root; i++) { if (p[i]) { f...
c574
class foo_params{ friend void foo(foo_params p); public: foo_params(int r): required_param_(r), optional_x_(0), optional_y_(1), optional_z_(3.1415) {} foo_params& x(int i){ optional_x_=i; return *this; } foo_params& y(int i){ optional_y_=i; return *this; } foo_params& z(flo...
c575
#include <iostream> #include <cstdlib> #include <ctime> int main() { std::srand(std::time(0)); int lower, upper, guess; std::cout << "Enter lower limit: "; std::cin >> lower; std::cout << "Enter upper limit: "; std::cin >> upper; int random_number = lower + std::rand() % ((upper + 1) - lowe...
c576
#include <iostream> #include <sstream> #include <algorithm> using namespace std; template <class S> class BestShuffle { public: BestShuffle() : rd(), g(rd()) {} S operator()(const S& s1) { S s2 = s1; shuffle(s2.begin(), s2.end(), g); for (unsigned i = 0; i < s2.length(); i++) ...
c577
#include <iostream> #include <cstdint> #include <limits> int main (int argc, char *argv[]) { std::cout << std::boolalpha << std::numeric_limits<std::int32_t>::is_modulo << '\n' << std::numeric_limits<std::uint32_t>::is_modulo << '\n' << std::numeric_limits<std::int64_t>::is_modulo << '\n' << std::numeric_li...
c578
#include <algorithm> #include <string> #include <vector> #include <iostream> template<class T> void print(const std::vector<T> &vec) { for (typename std::vector<T>::const_iterator i = vec.begin(); i != vec.end(); ++i) { std::cout << *i; if ((i + 1) != vec.end()) std::cout << ","; ...
c579
#include <iostream> #include <sstream> #include <algorithm> #include <vector> using namespace std; class poker { public: poker() { face = "A23456789TJQK"; suit = "SHCD"; } string analyze( string h ) { memset( faceCnt, 0, 13 ); memset( suitCnt, 0, 4 ); vector<string> hand; transform( h.begin(), h.end(), ...
c580
#include <algorithm> #include <iostream> #include <ostream> #include <vector> template<std::size_t> struct int_ {}; template <class Tuple, size_t Pos> std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos>) { out << std::get< std::tuple_size<Tuple>::value - Pos >(t) << ", "; return print_t...
c581
#ifndef PROCESSING_FLOODFILLALGORITHM_H_ #define PROCESSING_FLOODFILLALGORITHM_H_ #include <opencv2/opencv.hpp> #include <string.h> #include <queue> using namespace cv; using namespace std; class FloodFillAlgorithm { public: FloodFillAlgorithm(Mat* image) : image(image) { } virtual ~FloodFillAlgo...
c582
#include <initializer_list> #include <iostream> #include <map> #include <vector> struct Wheel { private: std::vector<char> values; size_t index; public: Wheel() : index(0) { } Wheel(std::initializer_list<char> data) : values(data), index(0) { if (values.size() < 1) { ...
c583
#include <ctime> #include <iostream> using namespace std; int identity(int x) { return x; } int sum(int num) { for (int i = 0; i < 1000000; i++) num += i; return num; } double time_it(int (*action)(int), int arg) { clock_t start_time = clock(); action(arg); clock_t finis_time = clock(); return ((doubl...
c584
#include <complex> #include <cmath> #include <iostream> using namespace std; template<int MSize = 3, class T = complex<double> > class SqMx { typedef T Ax[MSize][MSize]; typedef SqMx<MSize, T> Mx; private: Ax a; SqMx() { } public: SqMx(const Ax &_a) { for (int r = 0; r < MSize; r++) for (int c =...
c585
#include <algorithm> #include <iostream> #include <cmath> #include <set> #include <vector> using namespace std; bool find() { const auto MAX = 250; vector<double> pow5(MAX); for (auto i = 1; i < MAX; i++) pow5[i] = (double)i * i * i * i * i; for (auto x0 = 1; x0 < MAX; x0++) { for (aut...
c586
#include <boost/regex.hpp> #include <fstream> #include <iostream> #include <vector> #include <string> #include <set> #include <cstdlib> #include <algorithm> using namespace std ; boost::regex e ( "\\s+" ) ; int main( int argc , char *argv[ ] ) { ifstream infile( argv[ 1 ] ) ; vector<string> duplicates ; s...
c587
#include <iostream> #include <array> #include <string> using namespace std; int main() { const array<string, 12> days { "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "elevent...
c588
#include <algorithm> #include <bitset> #include <iostream> #include <vector> typedef unsigned long ulong; std::vector<ulong> primes; typedef struct { ulong p, e; } prime_factor; void sieve() { constexpr int SIZE = 1 << 16; std::bitset<SIZE> bits; bits.flip(); bits.reset(0); bits.reset...
c589
class Camera { }; class MobilePhone { }; class CameraPhone: public Camera, public MobilePhone { };
c590
#include <iostream> using namespace std; int main() { int cnt = 0, cnt2, cnt3, tmp, binary[8]; for (int i = 3; cnt < 25; i++) { tmp = i; cnt2 = 0; cnt3 = 0; for (int j = 7; j > 0; j--) { binary[j] = tmp % 2; tmp /= 2; } binary[0] = tmp; ...
c591
#include <cstdio> int main() { std::rename("input.txt", "output.txt"); std::rename("docs", "mydocs"); std::rename("/input.txt", "/output.txt"); std::rename("/docs", "/mydocs"); return 0; }
c592
#include <string> #include <algorithm> #include <iterator> #include <cstddef> #include <exception> #include <iostream> class not_found: public std::exception { public: not_found(std::string const& s): text(s + " not found") {} char const* what() const throw() { return text.c_str(); } ~not_found() throw() {} pri...
c593
class Abs { public: virtual int method1(double value) = 0; virtual int add(int a, int b){ return a+b; } };
c594
#include <iostream> #include <limits> using namespace std; void showTokens(int tokens) { cout << "Tokens remaining " << tokens << endl << endl; } int main() { int tokens = 12; while (true) { showTokens(tokens); cout << " How many tokens 1, 2 or 3? "; int t; cin >> t; ...
c595
#include <windows.h> #include <iostream> #include <string> using namespace std; class lastSunday { public: lastSunday() { m[0] = "JANUARY: "; m[1] = "FEBRUARY: "; m[2] = "MARCH: "; m[3] = "APRIL: "; m[4] = "MAY: "; m[5] = "JUNE: "; m[6] = "JULY: "; m[7] = "AUGUST: ";...
c596
#include <cstdlib> #include <fstream> #include <iomanip> #include <iostream> #include <string> bool is_vowel(char ch) { switch (ch) { case 'a': case 'A': case 'e': case 'E': case 'i': case 'I': case 'o': case 'O': case 'u': case 'U': return true; } return false; } bool alternat...
c597
#include <iostream> #include <vector> template <typename C, typename A> void merge2(const C& c1, const C& c2, const A& action) { auto i1 = std::cbegin(c1); auto i2 = std::cbegin(c2); while (i1 != std::cend(c1) && i2 != std::cend(c2)) { if (*i1 <= *i2) { action(*i1); i1 = s...
c598
#include <iostream> #include <vector> #include <iomanip> void primeFactors( unsigned n, std::vector<unsigned>& r ) { int f = 2; if( n == 1 ) r.push_back( 1 ); else { while( true ) { if( !( n % f ) ) { r.push_back( f ); n /= f; if( n == 1 ) return; ...
c599
#include <vector> #include <unordered_map> #include <iostream> int main() { std::vector<int> alreadyDiscovered; std::unordered_map<int, int> divsumMap; int count = 0; for (int N = 1; N <= 20000; ++N) { int divSumN = 0; for (int i = 1; i <= N / 2; ++i) { ...
c600
#include <string> std::string str; std::string str(); std::string str{}; std::string str(""); std::string str{""}; if (str.empty()) { ... } if (str.length() == 0) { ... } if (str == "") { ... } str.clear(); str = ""; str = {}; ...
c601
#include<string> #include<iostream> auto split(const std::string& input, const std::string& delim){ std::string res; for(auto ch : input){ if(!res.empty() && ch != res.back()) res += delim; res += ch; } return res; } int main(){ std::cout << split("gHHH5 ))YY++,,, }
c602
#include <cstdlib> #include <complex> template<typename ElementType, std::size_t dim1, std::size_t dim2> std::size_t get_first_dimension(ElementType (&a)[dim1][dim2]) { return dim1; } template<typename ElementType, std::size_t dim1, std::size_t dim2> std::size_t get_second_dimension(ElementType (&a)[dim1][dim2])...
c603
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
c604
#include <iostream> #include <complex> using std::complex; void complex_operations() { complex<double> a(1.0, 1.0); complex<double> b(3.14159, 1.25); std::cout << a + b << std::endl; std::cout << a * b << std::endl; std::cout << 1.0 / a << std::endl; std::cout << -a << std::endl; std::cou...
c605
#include <algorithm> #include <ctime> #include <iostream> #include <cstdlib> #include <string> using namespace std; int main() { srand(time(0)); unsigned int attributes_total = 0; unsigned int count = 0; int attributes[6] = {}; int rolls[4] = {}; while(attributes_total < 75 || count ...
c606
#include <iostream> #include <iomanip> #include <array> #include <string> #include <tuple> #include <algorithm> using namespace std; template<int N = 8> class Board { public: array<pair<int, int>, 8> moves; array<array<int, N>, N> data; Board() { moves[0] = make_pair(2, 1); moves[1] ...
c607
#include <iostream> int main() { std::cout << (int)'a' << std::endl; std::cout << (char)97 << std::endl; return 0; }
c608
#include <iostream> #include <map> int main() { const char* strings[] = {"133252abcdeeffd", "a6789798st", "yxcdfgxcyz"}; std::map<char, int> count; for (const char* str : strings) { for (; *str; ++str) ++count[*str]; } for (const auto& p : count) { if (p.second == 1) ...
c610
#include <iostream> #include <list> int main () { std::list<int> numbers {1, 5, 7, 0, 3, 2}; for(const auto& i: numbers) std::cout << i << ' '; std::cout << '\n'; }
c611
#include <time.h> #include <iostream> #include <string> using namespace std; class penney { public: penney() { pW = cW = 0; } void gameLoop() { string a; while( true ) { playerChoice = computerChoice = ""; if( rand() % 2 ) { computer(); player(); } else { player(); comput...
c613
#include <iostream> int main( ) { int current = 0 ; while ( ( current * current ) % 1000000 != 269696 ) current++ ; std::cout << "The square of " << current << " is " << (current * current) << " !\n" ; return 0 ; }
c614
#include <cstdlib> #include <iostream> #include <sstream> #include <iomanip> #include <list> bool k_prime(unsigned n, unsigned k) { unsigned f = 0; for (unsigned p = 2; f < k && p * p <= n; p++) while (0 == n % p) { n /= p; f++; } return f + (n > 1 ? 1 : 0) == k; } std::list<unsigned> primes(unsig...
c615
#include <iostream> #include <cmath> #include <cassert> using namespace std; #define PI 3.14159265359 class Vector { public: Vector(double ix, double iy, char mode) { if(mode=='a') { x=ix*cos(iy); y=ix*sin(iy); } else { x=ix; ...
c616
#include <cstdlib> #include <fstream> #include <iomanip> #include <iostream> #include <set> #include <string> int main(int argc, char** argv) { const char* filename(argc < 2 ? "unixdict.txt" : argv[1]); std::ifstream in(filename); if (!in) { std::cerr << "Cannot open file '" << filename << "'.\n"; ...
c617
#include <iostream> #include <string> #include <vector> std::vector<std::string> hist; std::ostream& operator<<(std::ostream& os, const std::string& str) { return os << str.c_str(); } void appendHistory(const std::string& name) { hist.push_back(name); } void hello() { std::cout << "Hello World!\n"; ...
c618
#include <windows.h> #include <ctime> #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 ); } ...
c619
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <ostream> #include <set> #include <vector> template<typename T> std::ostream& print(std::ostream& os, const T& src) { auto it = src.cbegin(); auto end = src.cend(); os << "["; if (it != end) { os << *it; ...
c620
#include <iostream> #include <stack> #include <string> #include <sstream> #include <vector> struct var { char name; bool value; }; std::vector<var> vars; template<typename T> T pop(std::stack<T> &s) { auto v = s.top(); s.pop(); return v; } bool is_operator(char c) { return c == '&' || c == '|...
c621
#include <iostream> int main() { const int N = 15; int t[N+2] = {0,1}; for(int i = 1; i<=N; i++){ for(int j = i; j>1; j--) t[j] = t[j] + t[j-1]; t[i+1] = t[i]; for(int j = i+1; j>1; j--) t[j] = t[j] + t[j-1]; std::cout << t[i+1] - t[i] << " "; } return 0; }
c622
#include <iostream> #include <string> std::string strip_white(const std::string& input) { size_t b = input.find_first_not_of(' '); if (b == std::string::npos) b = 0; return input.substr(b, input.find_last_not_of(' ') + 1 - b); } std::string strip_comments(const std::string& input, const std::string& delimite...
c623
#include <algorithm> #include <cstdlib> #include <fstream> #include <iomanip> #include <iostream> #include <set> #include <string> int main(int argc, char** argv) { const char* filename(argc < 2 ? "unixdict.txt" : argv[1]); std::ifstream in(filename); if (!in) { std::cerr << "Cannot open file '" <<...
c624
#include <utility> #include <algorithm> #include <array> #include <iterator> #include <iostream> template< class F, class Arg > struct PApply { F f; Arg arg; template< class F_, class Arg_ > PApply( F_&& f, Arg_&& arg ) : f(std::forward<F_>(f)), arg(std::forward<Arg_>(arg)) { } ...
c625
#include <string> #include <iostream> int main() { std::string s = "hello"; std::cout << s << " literal" << std::endl; std::string s2 = s + " literal"; std::cout << s2 << std::endl; return 0; }
c626
#include <boost/asio.hpp> int main() { boost::asio::io_context io_context; boost::asio::ip::tcp::socket sock(io_context); boost::asio::ip::tcp::resolver resolver(io_context); boost::asio::ip::tcp::resolver::query query("localhost", "4321"); boost::asio::connect(sock, resolver.resolve(query)); boost::asi...
c627
#include <iostream> enum class zd {N00,N01,N10,N11}; class N { private: int dVal = 0, dLen; void _a(int i) { for (;; i++) { if (dLen < i) dLen = i; switch ((zd)((dVal >> (i*2)) & 3)) { case zd::N00: case zd::N01: return; case zd::N10: if (((dVal >> ((i+1)*2)) & 1) != 1) return;...
c628
#include <iostream> #include <vector> #include <sstream> void print(std::vector<std::vector<double>> dist, std::vector<std::vector<int>> next) { std::cout << "(pair, dist, path)" << std::endl; const auto size = std::size(next); for (auto i = 0; i < size; ++i) { for (auto j = 0; j < size; ++j) { if (i !...
c629
#include <gtkmm.h> int main(int argc, char *argv[]) { Gtk::Main app(argc, argv); Gtk::MessageDialog msg("Goodbye, World!"); msg.run(); }
c630
#include <iostream> int digitSum(int n) { int s = 0; do {s += n % 10;} while (n /= 10); return s; } int main() { for (int i=0; i<1000; i++) { auto s_i = std::to_string(i); auto s_ds = std::to_string(digitSum(i)); if (s_i.find(s_ds) != std::string::npos) { std::cout ...
c631
#include <vector> #include <string> #include <iostream> #include <ctime> class Date { struct tm ltime; public: Date() { time_t t = time(0); localtime_r(&t, &ltime); } std::string getDate(const char* fmt) { char out[200]; size_t result = strfti...
c632
#include <vector> #include <boost/date_time/gregorian/gregorian.hpp> #include <algorithm> #include <iostream> #include <iterator> using namespace boost::gregorian ; void print( const date &d ) { std::cout << d.year( ) << "-" << d.month( ) << "\n" ; } int main( ) { greg_month longmonths[ ] = {Jan, Mar , May , Ju...
c633
#include <cctype> #include <iomanip> #include <iostream> #include <list> #include <memory> #include <sstream> #include <string> #include <variant> namespace s_expr { enum class token_type { none, left_paren, right_paren, symbol, string, number }; enum class char_type { left_paren, right_paren, quote, escape, space, o...
c634
#include <iostream> #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/integer.hpp> int main() { using boost::multiprecision::cpp_int; using boost::multiprecision::pow; using boost::multiprecision::powm; cpp_int a("2988348162058574136915891421498819466320163312926952423791023078...
c635
T* p = new T[n]; for(size_t i = 0; i != n; ++i) p[i] = make_a_T(); delete[] p;
c636
#include <iostream> #include <vector> using namespace std; typedef unsigned int uint; class NarcissisticDecs { public: void makeList( int mx ) { uint st = 0, tl; int pwr = 0, len; while( narc.size() < mx ) { len = getDigs( st ); if( pwr != len ) { pwr = len; fillPower( pwr ); ...
c637
#include <iostream> #include <stack> #include <string> #include <map> #include <set> using namespace std; struct Entry_ { string expr_; string op_; }; bool PrecedenceLess(const string& lhs, const string& rhs, bool assoc) { static const map<string, int> KNOWN({ { "+", 1 }, { "-", 1 }, { "*", 2 }, { "/", 2 }, { ...
c638
#include <iostream> using namespace std; int main(int argc, char **argv) { char *program = argv[0]; cout << "Program: " << program << endl; }
c639
#include <iomanip> #include <iostream> #include <vector> class Node { private: double v; int fixed; public: Node() : v(0.0), fixed(0) { } Node(double v, int fixed) : v(v), fixed(fixed) { } double getV() const { return v; } void setV(double nv) { ...
c640
#include <cassert> #include <algorithm> #include <iomanip> #include <iostream> #include <vector> #include <gmpxx.h> using big_int = mpz_class; bool is_prime(const big_int& n) { return mpz_probab_prime_p(n.get_mpz_t(), 25); } template <typename integer> class n_smooth_generator { public: explicit n_smooth_gen...
c641
#include <boost/beast/core.hpp> #include <boost/beast/http.hpp> #include <boost/beast/version.hpp> #include <boost/asio/connect.hpp> #include <boost/asio/ip/tcp.hpp> #include <iostream> #include <string> bool get_mac_vendor(const std::string& mac, std::string& vendor) { namespace beast = boost::beast; names...
c642
#include <vector> #include <iostream> #include <numeric> #include <cmath> #include <algorithm> double toInverse ( int i ) { return 1.0 / i ; } int main( ) { std::vector<int> numbers ; for ( int i = 1 ; i < 11 ; i++ ) numbers.push_back( i ) ; double arithmetic_mean = std::accumulate( numbers.begin...
c643
#include <iomanip> #include <iostream> #include <vector> #define _USE_MATH_DEFINES #include <math.h> template<typename C> double meanAngle(const C& c) { auto it = std::cbegin(c); auto end = std::cend(c); double x = 0.0; double y = 0.0; double len = 0.0; while (it != end) { x += cos(*i...
c644
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <iterator> #include <sstream> int main() { std::string s = "rosetta code phrase reversal"; std::cout << "Input : " << s << '\n' << "Input reversed : " << std::string(s.rbegin(), s.rend()) << '\n' ; std::istrings...
c645
#include <gmpxx.h> #include <algorithm> #include <cassert> #include <functional> #include <iostream> #include <vector> using big_int = mpz_class; const unsigned int small_primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, ...
c646
#include <iostream> bool sameDigits(int n, int b) { int f = n % b; while ((n /= b) > 0) { if (n % b != f) { return false; } } return true; } bool isBrazilian(int n) { if (n < 7) return false; if (n % 2 == 0)return true; for (int b = 2; b < n - 1; b++) { ...
c647
#include <iostream> int main() { int a, b; if (!(std::cin >> a >> b)) { std::cerr << "could not read the numbers\n"; return 1; } if (a < b) std::cout << a << " is less than " << b << "\n"; if (a == b) std::cout << a << " is equal to " << b << "\n"; if (a > b) std::cout << a...
c648
#include <iostream> #include <iomanip> int main() { for (int i = 0; i <= 33; i++) std::cout << std::setw(6) << std::dec << i << " " << std::setw(6) << std::hex << i << " " << std::setw(6) << std::oct << i << std::endl; return 0; }
c649
#include <iostream> #include <sstream> #include <algorithm> #include <vector> #include <string> std::string findLargestConcat ( std::vector< int > & mynumbers ) { std::vector<std::string> concatnumbers ; std::sort ( mynumbers.begin( ) , mynumbers.end( ) ) ; do { std::ostringstream numberstream ; f...
c650
#include <set> #include <algorithm> #include <string> #include <iostream> #include <vector> #include <numeric> std::set<std::string> createPrefixes ( const std::string & s ) { std::set<std::string> result ; for ( int i = 1 ; i < s.size( ) + 1 ; i++ ) result.insert( s.substr( 0 , i )) ; return result ; }...
c651
#include <iostream> #include <tuple> #include <vector> using namespace std; double shoelace(vector<pair<double, double>> points) { double leftSum = 0.0; double rightSum = 0.0; for (int i = 0; i < points.size(); ++i) { int j = (i + 1) % points.size(); leftSum += points[i].first * points[j].second; rightSum ...
c652
#include <iostream> #include <iomanip> #include <vector> #include <algorithm> #include <iterator> std::vector<int> GenerateFactors(int n) { std::vector<int> factors = { 1, n }; for (int i = 2; i * i <= n; ++i) { if (n % i == 0) { factors.push_back(i); if (i * i != n) ...
c653
void print_logic(bool a, bool b) { std::cout << std::boolalpha; std::cout << "a and b is " << (a && b) << "\n"; std::cout << "a or b is " << (a || b) << "\n"; std::cout << "not a is " << (!a) << "\n"; }
c654
#include <random> #include <map> #include <string> #include <iostream> #include <cmath> #include <iomanip> int main( ) { std::random_device myseed ; std::mt19937 engine ( myseed( ) ) ; std::normal_distribution<> normDistri ( 2 , 3 ) ; std::map<int , int> normalFreq ; int sum = 0 ; double mean = 0.0 ...