_id
stringlengths
2
5
text
stringlengths
7
10.9k
title
stringclasses
1 value
c756
#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << a + b << endl; }
c757
#include <iostream> #include "math.h" #include "boost/rational.hpp" typedef boost::rational<int> frac; bool is_perfect(int c) { frac sum(1, c); for (int f = 2;f < sqrt(static_cast<float>(c)); ++f){ if (c % f == 0) sum += frac(1,f) + frac(1, c/f); } if (sum.denominator() == 1){ return (sum ...
c758
#include <cmath> #include <iostream> #include <numbers> static const double DegreesPerHour = 15.0; static const double DegreesPerRadian = 180.0 * std::numbers::inv_pi; struct SundialCalculation { double HourAngle; double HourLineAngle; }; class Sundial { double m_sinLatitude; double m_timeZoneCorrectio...
c759
#include <iostream> #include <iterator> #include <vector> using namespace std; typedef vector<double> Poly; void Print(char name, const Poly &A) { cout << name << "(" << A.size()-1 << ") = [ "; copy(A.begin(), A.end(), ostream_iterator<decltype(A[0])>(cout, " ")); cout << "]\n"; } int main() { Poly N, D, d, q...
c760
#include <iostream> #include <numeric> #include <functional> #include <vector> int main() { std::vector<int> nums = { 1, 2, 3, 4, 5 }; auto nums_added = std::accumulate(std::begin(nums), std::end(nums), 0, std::plus<int>()); auto nums_other = std::accumulate(std::begin(nums), std::end(nums), 0, [](const int& a, con...
c761
#include <string> #include "Poco/URI.h" #include <iostream> int main( ) { std::string encoded( "http%3A%2F%2Ffoo%20bar%2F" ) ; std::string decoded ; Poco::URI::decode ( encoded , decoded ) ; std::cout << encoded << " is decoded: " << decoded << " !" << std::endl ; return 0 ; }
c762
#include <chrono> #include <csignal> #include <ctime> #include <iostream> #include <thread> volatile sig_atomic_t gotint = 0; void handler(int signum) { gotint = 1; } int main() { using namespace std; signal(SIGINT, handler); int i = 0; clock_t startTime = clock(); while (true) { if (gotint) break; std...
c763
#include <iostream> int main() { unsigned int a = 1, b = 1; unsigned int target = 48; for(unsigned int n = 3; n <= target; ++n) { unsigned int fib = a + b; std::cout << "F("<< n << ") = " << fib << std::endl; a = b; b = fib...
c764
int i = 1024; while(i > 0){ std::cout << i << std::endl; i /= 2; }
c765
#include <iostream> double f(double x); int main() { unsigned int start = 1; unsigned int end = 1000; double sum = 0; for( unsigned int x = start; x <= end; ++x ) { sum += f(x); } std::cout << "Sum of f(x) from " << start << " to " << end << " is " << sum << std::endl; return ...
c766
#include <cassert> #include <iostream> typedef unsigned long ulong; ulong egyptian_division(ulong dividend, ulong divisor, ulong* remainder) { constexpr int SIZE = 64; ulong powers[SIZE]; ulong doublings[SIZE]; int i = 0; for (; i < SIZE; ++i) { powers[i] = 1 << i; doublings[i] =...
c767
template<class ForwardIterator> void combsort ( ForwardIterator first, ForwardIterator last ) { static const double shrink_factor = 1.247330950103979; typedef typename std::iterator_traits<ForwardIterator>::difference_type difference_type; difference_type gap = std::distance(first, last); bool swaps = t...
c768
#include <iostream> #include <algorithm> #include <vector> #include <numeric> void partitions(std::vector<size_t> args) { size_t sum = std::accumulate(std::begin(args), std::end(args), 0); std::vector<size_t> nums(sum); std::iota(std::begin(nums), std::end(nums), 1); do { size_t total_index = 0; std::v...
c769
#include <iostream> #include <string> #include <vector> struct last_letter_first_letter { size_t max_path_length = 0; size_t max_path_length_count = 0; std::vector<std::string> max_path_example; void search(std::vector<std::string>& names, size_t offset) { if (offset > max_path_length) { ...
c770
#include <windows.h> #include <string> using namespace std; const int BMP_SIZE = 600, CELL_SIZE = 4, GRID_SIZE = BMP_SIZE / CELL_SIZE; const bool INFINIT_RUN = false; enum cellState { WHITE, BLACK, ANT }; enum facing { NOR, EAS, SOU, WES }; enum state { RUNNING, RESTING }; class myBitmap { public: myBitmap()...
c771
#include <iostream> #include <fstream> #include <string> #include <map> #include <vector> #include <algorithm> #include <iterator> int main() { std::ifstream in("unixdict.txt"); typedef std::map<std::string, std::vector<std::string> > AnagramMap; AnagramMap anagrams; std::string word; size_t count = 0; ...
c772
#include <cstdlib> void problem_occured() { std::exit(EXIT_FAILURE); }
c774
#include <iostream> #include <vector> using namespace std; int doStuff(int a, int b) { return a + b; } int main() { int t; cin >> t; vector<pair<int, int>> list(t); for(int j=0; j<t; j++){ cin >> list[j].first >> list[j].second; } cout << endl; for(int j=0;j<t;j++){ cout << doStuff(list[j].fir...
c775
inline double multiply(double a, double b) { return a*b; }
c776
#include <array> #include <iomanip> #include <iostream> const int MC = 103 * 1000 * 10000 + 11 * 9 + 1; std::array<bool, MC + 1> SV; void sieve() { std::array<int, 10000> dS; for (int a = 9, i = 9999; a >= 0; a--) { for (int b = 9; b >= 0; b--) { for (int c = 9, s = a + b; c >= 0; c--) { ...
c777
#include <algorithm> #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, scalar_type val...
c778
#include <iostream> #include <functional> #include <vector> int main() { std::vector<std::function<int()> > funcs; for (int i = 0; i < 10; i++) funcs.push_back([=]() { return i * i; }); for ( std::function<int( )> f : funcs ) std::cout << f( ) << std::endl ; return 0; }
c779
#include <iostream> #include <numeric> #include <sstream> #include <vector> class Frac { public: Frac(long n, long d) { if (d == 0) { throw new std::runtime_error("d must not be zero"); } long nn = n; long dd = d; if (nn == 0) { dd = 1; } else if (dd < 0) { nn = -nn; dd = -dd; } long g =...
c780
#include <iostream> #include <vector> #include <string> #include <set> #include <cctype> typedef std::pair<char,char> item_t; typedef std::vector<item_t> list_t; bool can_make_word(const std::string& w, const list_t& vals) { std::set<uint32_t> used; while (used.size() < w.size()) { const char c = toup...
c781
#include <string> #include <iostream> #include "Poco/SHA1Engine.h" #include "Poco/DigestStream.h" using Poco::DigestEngine ; using Poco::SHA1Engine ; using Poco::DigestOutputStream ; int main( ) { std::string myphrase ( "Rosetta Code" ) ; SHA1Engine sha1 ; DigestOutputStream outstr( sha1 ) ; outstr << myp...
c782
#include <gmpxx.h> int N{123456}; mpz_class hyp[N-3]; const mpz_class G(const int n,const int g){return g>n?0:(g==1 or n-g<2)?1:hyp[n-g-2];}; void G_hyp(const int n){for(int i=0;i<N-2*n-1;i++) n==1?hyp[n-1+i]=1+G(i+n+1,n+1):hyp[n-1+i]+=G(i+n+1,n+1);} }
c783
#include <iostream> #include <string> #include <climits> using namespace std; class BalancedTernary { protected: string value; int charToInt(char c) const { if (c == '0') return 0; return 44 - c; } string negate(string s) const { for (int i = 0; i < s.length(); ++i) { if (s[i] == '+') s[i] ...
c784
#include <iostream> #include <vector> __int128 imax(__int128 a, __int128 b) { if (a > b) { return a; } return b; } __int128 ipow(__int128 b, __int128 n) { if (n == 0) { return 1; } if (n == 1) { return b; } __int128 res = b; while (n > 1) { res *= b...
c785
#include <iostream> bool isPrime(uint64_t n) { if (n < 2) return false; if (n % 2 == 0) return n == 2; if (n % 3 == 0) return n == 3; uint64_t test = 5; while (test * test < n) { if (n % test == 0) return false; test += 2; if (n % test == 0) return false; test += 4;...
c786
#include <cstdint> #include <functional> #include <iomanip> #include <iostream> uint32_t hpo2(uint32_t n) { return n & -n; } uint32_t lhpo2(uint32_t n) { uint32_t q = 0, m = hpo2(n); for (; m % 2 == 0; m >>= 1, ++q) {} return q; } uint32_t nimsum(uint32_t x, uint32_t y) { return x ^ y; } uin...
c787
#include <iostream> #include <vector> int main(int argc, char* argv[]) { std::vector<char> ls(3); ls[0] = 'a'; ls[1] = 'b'; ls[2] = 'c'; std::vector<char> us(3); us[0] = 'A'; us[1] = 'B'; us[2] = 'C'; std::vector<int> ns(3); ns[0] = 1; ns[1] = 2; ns[2] = 3; std::vector<char>::const_iterator lIt = ls....
c788
#include <iostream> template< class T > class D3Vector { template< class U > friend std::ostream & operator<<( std::ostream & , const D3Vector<U> & ) ; public : D3Vector( T a , T b , T c ) { x = a ; y = b ; z = c ; } T dotproduct ( const D3Vector & rhs ) { T scalar = x * rhs.x + ...
c789
struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; ListNode* Solution::detectCycle(ListNode* A) { ListNode* slow = A; ListNode* fast = A; ListNode* cycleNode = 0; while (slow && fast && fast->next) { slow = slow->next; fast = fa...
c790
template <class T> int binsearch(const T array[], int low, int high, T value) { if (high < low) { return -1; } auto mid = (low + high) / 2; if (value < array[mid]) { return binsearch(array, low, mid - 1, value); } else if (value > array[mid]) { return binsearch(array, mid + 1...
c791
#include <string> #include <iostream> #include <algorithm> template<typename char_type> std::basic_string<char_type> collapse(std::basic_string<char_type> str) { auto i = std::unique(str.begin(), str.end()); str.erase(i, str.end()); return str; } void test(const std::string& str) { std::cout << "origi...
c793
#include <string> #include <iostream> #include <boost/algorithm/string.hpp> #include <map> #include <algorithm> #include <cctype> using namespace boost::algorithm; bool isValid(const std::string &ibanstring) { static std::map<std::string, int> countrycodes { {"AL", 28}, {"AD", 24}, {"AT", 20}, {"AZ", 28 }...
c794
#include <iostream> #include <ranges> int main() { const int maxSquareDiff = 1000; auto squareCheck = [maxSquareDiff](int i){return 2 * i - 1 > maxSquareDiff;}; auto answer = std::views::iota(1) | std::views::filter(squareCheck) | std::views::take(1); std::cout << answer....
c795
#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...
c796
#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; if (n % p == 0) ...
c797
#include <iostream> #include <random> #include <vector> double equalBirthdays(int nSharers, int groupSize, int nRepetitions) { std::default_random_engine generator; std::uniform_int_distribution<int> distribution(0, 364); std::vector<int> group(365); int eq = 0; for (int i = 0; i < nRepetitions; i...
c798
#include <iostream> #include <sstream> int main() { int num; std::istringstream("0123459") >> num; std::cout << num << std::endl; std::istringstream("0123459") >> std::dec >> num; std::cout << num << std::endl; std::istringstream("abcf123") >> std::hex >> num; std::cout << num << std::endl; std:...
c800
#include <iostream> #include <iomanip> #define MAX 120 using namespace std; bool is_prime(int n) { if (n < 2) return false; if (!(n % 2)) return n == 2; if (!(n % 3)) return n == 3; int d = 5; while (d *d <= n) { if (!(n % d)) return false; d += 2; if (!(n % d)) return ...
c801
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; const char *men_data[][11] = { { "abe", "abi","eve","cath","ivy","jan","dee","fay","bea","hope","gay" }, { "bob", "cath","hope","abi","dee","eve","fay","bea","jan","ivy","gay" }, ...
c802
#include <iostream> const char *CREATURES[] = { "fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse" }; const char *COMMENTS[] = { "I don't know why she swallowed that fly.\nPerhaps she'll die\n", "That wiggled and jiggled and tickled inside her", "How absurd, to swallow a bird", "Imagine that...
c803
#define _USE_MATH_DEFINES #include <math.h> #include <iostream> const static double EarthRadiusKm = 6372.8; inline double DegreeToRadian(double angle) { return M_PI * angle / 180.0; } class Coordinate { public: Coordinate(double latitude ,double longitude):myLatitude(latitude), myLongitude(longitude) {} double...
c804
#include <iostream> #include <gmpxx.h> static bool is_mersenne_prime(mpz_class p) { if( 2 == p ) return true; else { mpz_class s(4); mpz_class div( (mpz_class(1) << p.get_ui()) - 1 ); for( mpz_class i(3); i <= p; ++i ) ...
c805
#include <boost/filesystem/operations.hpp> #include <ctime> #include <iostream> int main( int argc , char *argv[ ] ) { if ( argc != 2 ) { std::cerr << "Error! Syntax: moditime <filename>!\n" ; return 1 ; } boost::filesystem::path p( argv[ 1 ] ) ; if ( boost::filesystem::exists( p ) ) { st...
c806
#include <algorithm> #include <iostream> #include <numeric> #include <vector> void polyRegression(const std::vector<int>& x, const std::vector<int>& y) { int n = x.size(); std::vector<int> r(n); std::iota(r.begin(), r.end(), 0); double xm = std::accumulate(x.begin(), x.end(), 0.0) / x.size(); doubl...
c807
#include <iostream> #include <cstdlib> #include <ctime> int randint(int n) { return (1.0*n*std::rand())/(1.0+RAND_MAX); } int other(int doorA, int doorB) { int doorC; if (doorA == doorB) { doorC = randint(2); if (doorC >= doorA) ++doorC; } else { for (doorC = 0; doorC == doorA || door...
c808
using namespace System; using namespace System::Drawing; using namespace System::Windows::Forms; [STAThreadAttribute] int main() { Point^ MousePoint = gcnew Point(); Control^ TempControl = gcnew Control(); MousePoint = TempControl->MousePosition; Bitmap^ TempBitmap = gcnew Bitmap(1,1); Graphics^ g = Graphics::Fro...
c809
#include <iostream> #include <iomanip> using namespace std; void getPrimeFactors( int li ) { int f = 2; string res; if ( li == 1 ) res = "1"; else { while ( true ) { if( !( li % f ) ) { res += to_string(f); li /= f; if( li == 1 ) break; res += " x "; } else f++; } } ...
c810
#include <iostream> #include <fstream> #include <string> #include <tuple> #include <vector> #include <stdexcept> #include <boost/regex.hpp> struct Claim { Claim(const std::string& name) : name_(name), pro_(0), against_(0), propats_(), againstpats_() { } void add_pro(const std::string...
c811
#include <bitset> #include <iostream> #include <limits> #include <string> void print_bin(unsigned int n) { std::string str = "0"; if (n > 0) { str = std::bitset<std::numeric_limits<unsigned int>::digits>(n).to_string(); str = str.substr(str.find('1')); } std::cout << str << '\n'; } int main() {...
c812
template<typename T> void insert_after(link<T>* list_node, link<T>* new_node) { new_node->next = list_node->next; list_node->next = new_node; };
c813
#include <iostream> #include <fstream> int main() { std::string word; std::ifstream file("unixdict.txt"); if (!file) { std::cerr << "Cannot open unixdict.txt" << std::endl; return -1; } while (file >> word) { if (word.length() > 11 && word.find("the") != std::string::npos)...
c814
#include <iostream> #include <iomanip> #include <string> #include <cmath> #include <utility> #include <vector> using namespace std; static const double PI = acos(-1.0); double affine_remap(const pair<double, double>& from, double x, const pair<double, double>& to) { return to.first + (x - from.first) * (to.second -...
c815
#include <iostream> #include <numeric> #include <vector> double add_square(double prev_sum, double new_val) { return prev_sum + new_val*new_val; } double vec_add_squares(std::vector<double>& v) { return std::accumulate(v.begin(), v.end(), 0.0, add_square); } int main() { std::vector<double> v; std::cout ...
c816
#include <iostream> #include <iomanip> #include <algorithm> #include <string> #include <set> #include <map> using namespace std; class Expression{ private: enum { NUMBER_OF_DIGITS = 9 }; enum Op { ADD, SUB, JOIN }; int code[NUMBER_OF_DIGITS]; public: static const int NUMBER_O...
c817
#include <iostream> #include <limits> int main() { float currentAverage = 0; unsigned int currentEntryNumber = 0; for (;;) { int entry; std::cout << "Enter rainfall int, 99999 to quit: "; std::cin >> entry; if (!std::cin.fail()) { if (entry == 99999) { std::cout << "User requested quit....
c818
#include <numeric> #include <functional> int arg[] = { 1, 2, 3, 4, 5 }; int sum = std::accumulate(arg, arg+5, 0, std::plus<int>()); int prod = std::accumulate(arg, arg+5, 1, std::multiplies<int>());
c819
#include <boost/algorithm/string.hpp> #include <string> #include <iostream> int main( ) { std::string testphrase( " There are unwanted blanks here! " ) ; std::string lefttrimmed = boost::trim_left_copy( testphrase ) ; std::string righttrimmed = boost::trim_right_copy( testphrase ) ; std::cout << "The...
c820
#include <iostream> using namespace std; int F(int n,int x,int y) { if (n == 0) { return x + y; } else if (y == 0) { return x; } return F(n - 1, F(n, x, y - 1), F(n, x, y - 1) + y); } int main() { cout << "F(1,3,3) = "<<F(1,3,3)<<endl; return 0; }
c821
#include <iostream> #include <string> int main( ) { std::string original ("This is the original"); std::string my_copy = original; std::cout << "This is the copy: " << my_copy << std::endl; original = "Now we change the original! "; std::cout << "my_copy still is " << my_copy << std::endl; }
c822
#include <iostream> #include <cmath> int SumDigits(const unsigned long long int digits, const int BASE = 10) { int sum = 0; unsigned long long int x = digits; for (int i = log(digits)/log(BASE); i>0; i--){ const double z = std::pow(BASE,i); const unsigned long long int t = x/z; sum += t; x ...
c823
#include <array> #include <iostream> #include <string> int main() { std::array<std::string, 2> fruit { "apples", "oranges" }; std::cout << fruit.size(); return 0; }
c824
#include <algorithm> #include <iterator> #include <functional> template<class It, class Comp = std::less<>> constexpr auto max_value(It first, It last, Comp compare = std::less{}) { return *std::max_element(first, last, compare); } template<class C, class Comp = std::less<>> constexpr auto ma...
c825
#include <iostream> template<typename T> void print(T const& t) { std::cout << t; } template<typename First, typename ... Rest> void print(First const& first, Rest const& ... rest) { std::cout << first; print(rest ...); } int main() { int i = 10; std::string s = "Hello world"; print("i = ", i, " and s ...
c826
#include <iostream> int main() { std::cout << ( (727 == 0x2d7) && (727 == 01327) ? "true" : "false") << std::endl; return 0; }
c827
#include <vector> #include <memory> #include <cmath> #include <iostream> #include <iomanip> using namespace std; typedef vector< int > IntRow; typedef vector< IntRow > IntTable; auto_ptr< IntTable > getZigZagArray( int dimension ) { auto_ptr< IntTable > zigZagArrayPtr( new IntTable( dimension, IntRow( dimensio...
c828
#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/xmlstring.h> #include <libxml/xmlversion.h> #include <libxml/xpath.h> #ifndef LIBXML_XPATH_ENABLED # e...
c829
#include <windows.h> #include <ctime> #include <string> const int BMP_SIZE = 600, ITERATIONS = static_cast<int>( 15e5 ); class myBitmap { public: myBitmap() : pen( NULL ), brush( NULL ), clr( 0 ), wid( 1 ) {} ~myBitmap() { DeleteObject( pen ); DeleteObject( brush ); DeleteDC( hdc ); DeleteObje...
c830
#include <iostream> #include <utility> #include <complex> typedef std::complex<double> complex; std::pair<complex, complex> solve_quadratic_equation(double a, double b, double c) { b /= a; c /= a; double discriminant = b*b-4*c; if (discriminant < 0) return std::make_pair(complex(-b/2, std::sqrt(-discrimi...
c831
#include <iostream> #include <cstdint> typedef uint64_t integer; integer bit_count(integer n) { integer count = 0; for (; n > 0; count++) n >>= 1; return count; } integer mod_pow(integer p, integer n) { integer square = 1; for (integer bits = bit_count(p); bits > 0; square %= n) { ...
c832
#include <iomanip> #include <iostream> using namespace std; const int pasTriMax = 61; uint64_t pasTri[pasTriMax + 1]; void pascalTriangle(unsigned long n) { unsigned long j, k; pasTri[0] = 1; j = 1; while (j <= n) { j++; k = j / 2; pasTri[k] = pasTri[k - 1]; for ...
c833
#include <iostream> #include <iterator> #include <vector> #include <ppl.h> #include <concurrent_vector.h> struct Factors { int number; std::vector<int> primes; }; const int data[] = { 12757923, 12878611, 12878893, 12757923, 15808973, 15780709, 197622519 }; int main() { Concurrency::concurrent_...
c834
#include <algorithm> int main() { int nums[] = {2,4,3,1,2}; std::sort(nums, nums+sizeof(nums)/sizeof(int)); return 0; }
c835
#include <iostream> #include <cryptopp/filters.h> #include <cryptopp/hex.h> #include <cryptopp/sha.h> int main(int argc, char **argv){ CryptoPP::SHA256 hash; std::string digest; std::string message = "Rosetta code"; CryptoPP::StringSource s(message, true, new CryptoPP::HashFilter(hash, new CryptoPP::HexEnc...
c836
#include <math.h> #include <iostream> unsigned pwr[10]; unsigned munch( unsigned i ) { unsigned sum = 0; while( i ) { sum += pwr[(i % 10)]; i /= 10; } return sum; } int main( int argc, char* argv[] ) { for( int i = 0; i < 10; i++ ) pwr[i] = (unsigned)pow( (float)i, (float)...
c837
#include <bit> #include <iostream> int main() { std::cout << "int is " << sizeof(int) << " bytes\n"; std::cout << "a pointer is " << sizeof(int*) << " bytes\n\n"; if (std::endian::native == std::endian::big) { std::cout << "platform is big-endian\n"; } else { std::cout << "...
c838
#include <vector> #include <iostream> #include <numeric> #include <iterator> #include <memory> #include <string> #include <algorithm> #include <iomanip> std::vector<int> nacci ( const std::vector<int> & start , int arity ) { std::vector<int> result ( start ) ; int sumstart = 1 ; while ( ...
c839
#include <iostream> #include <random> std::default_random_engine generator; bool biased(int n) { std::uniform_int_distribution<int> distribution(1, n); return distribution(generator) == 1; } bool unbiased(int n) { bool flip1, flip2; do { flip1 = biased(n); flip2 = biased(n); ...
c840
#include <iostream> #include <vector> int main() { int numberOfLines; std::cin >> numberOfLines; std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); std::vector<std::string> lines(numberOfLines); for(int i = 0; i < numberOfLines; ++i) { std::getline(s...
c841
#include <iostream> int main() { std::cout << "Goodbye, World!"; return 0; }
c842
#include <iostream> #include <blitz/tinymat.h> int main() { using namespace blitz; TinyMatrix<double,3,3> A, B, C; A = 1, 2, 3, 4, 5, 6, 7, 8, 9; B = 1, 0, 0, 0, 1, 0, 0, 0, 1; C = product(A, B); std::cout << C << std::endl; }
c843
#include <limits> double inf() { if (std::numeric_limits<double>::has_infinity) return std::numeric_limits<double>::infinity(); else return std::numeric_limits<double>::max(); }
c844
#include <iostream> #include <vector> bool isCusip(const std::string& s) { if (s.size() != 9) return false; int sum = 0; for (int i = 0; i <= 7; ++i) { char c = s[i]; int v; if ('0' <= c && c <= '9') { v = c - '0'; } else if ('A' <= c && c <= 'Z') { ...
c845
#ifndef MYWIDGET_H #define MYWIDGET_H #include <QWidget> class QPaintEvent ; class MyWidget : public QWidget { public : MyWidget( ) ; protected : void paintEvent( QPaintEvent * ) ; } ; #endif
c846
#include <iostream> int main() { const int max_it = 13; const int max_it_j = 10; double a1 = 1.0, a2 = 0.0, d1 = 3.2; std::cout << " i d\n"; for (int i = 2; i <= max_it; ++i) { double a = a1 + (a1 - a2) / d1; for (int j = 1; j <= max_it_j; ++j) { double x = 0.0; ...
c847
#include <algorithm> #include <functional> #include <iostream> #include <vector> std::vector<int> primes; struct Seq { public: bool empty() { return p < 0; } int front() { return p; } void popFront() { if (p == 2) { p++; } else { p += 2; ...
c848
#include <string> #include <sstream> #include <vector> #include <iterator> #include <iostream> #include <algorithm> int main() { std::string s = "Hello,How,Are,You,Today"; std::vector<std::string> v; std::istringstream buf(s); for(std::string token; getline(buf, token, ','); ) v.push_back(token)...
c849
#include <iostream> #include <gmpxx.h> template<typename Integer, typename OutputIterator> void decompose(Integer n, OutputIterator out) { Integer i(2); while (n != 1) { while (n % i == Integer(0)) { *out++ = i; n /= i; } ++i; } } template<typename T> class infix_ostrea...
c850
#include <iostream> #include <vector> #include <utility> std::vector<int> hailstone(int i) { std::vector<int> v; while(true){ v.push_back(i); if (1 == i) break; i = (i % 2) ? (3 * i + 1) : (i / 2); } return v; } std::pair<int,int> find_longest_hailstone_seq(int n) { std::...
c852
#include <iostream> #include <cmath> int main() { std::cout << "(5 ^ 3) ^ 2 = " << (uint) pow(pow(5,3), 2) << std::endl; std::cout << "5 ^ (3 ^ 2) = "<< (uint) pow(5, (pow(3, 2))); return EXIT_SUCCESS; }
c853
#include <iostream> #include <bitset> #include <string> const int ArraySize = 20; const int NumGenerations = 10; const std::string Initial = "0011101101010101001000"; int main() { std::bitset<ArraySize + 2> array(Initial); for(int j = 0; j < NumGenerations; ++j) { std::bitset<ArraySize + 2> ...
c854
#include <iostream> #include <chrono> #include <ctime> int main() { std::chrono::system_clock::time_point epoch; std::time_t t = std::chrono::system_clock::to_time_t(epoch); std::cout << std::asctime(std::gmtime(&t)) << '\n'; return 0; }
c855
#include <string> #include <iostream> #include <algorithm> #include <cctype> class MyTransform { private : int shift ; public : MyTransform( int s ) : shift( s ) { } char operator( )( char c ) { if ( isspace( c ) ) return ' ' ; else { static std::string letters( "abcdefghijklmnopqrstuvwxyz"...
c856
#include <algorithm> #include <iostream> #include <utility> #include <vector> template <typename iterator> void normalize_ranges(iterator begin, iterator end) { for (iterator i = begin; i != end; ++i) { if (i->second < i->first) std::swap(i->first, i->second); } std::sort(begin, end);...
c857
#include <array> #include <iostream> void require(bool condition, const std::string &message) { if (condition) { return; } throw std::runtime_error(message); } template<typename T, size_t N> std::ostream &operator<<(std::ostream &os, const std::array<T, N> &a) { auto it = a.cbegin(); auto ...
c858
#include <iostream> int main() { int Base = 10; const int N = 2; int c1 = 0; int c2 = 0; for (int k=1; k<pow((double)Base,N); k++){ c1++; if (k%(Base-1) == (k*k)%(Base-1)){ c2++; std::cout << k << " "; } } std::cout << "\nTrying " << c2 << " numbers instead of " << c1 << " numbers saves " << 100 ...
c859
#include <iostream> struct link { link* next; int data; link(int newItem, link* head) : next{head}, data{newItem}{} }; void PrintList(link* head) { if(!head) return; std::cout << head->data << " "; PrintList(head->next); } link* RemoveItem(int valueToRemove, link*&head) { for(link...