程序代码:
#include <iostream> #include <numeric> using namespace std; int main( void ) { unsigned a, b; if( !(cin>>a>>b) ) return 1; cout << lcm(a,b) << endl; }
#include <iostream> #include <iterator> #include <numeric> #include <algorithm> using namespace std; int main( void ) { unsigned a[28]; copy_n( std::istream_iterator<unsigned>(cin), size(a), a ); double avg = std::accumulate(begin(a),end(a),0.0) / size(a); copy_if( begin(a), end(a), std::ostream_iterator<unsigned>(cout," "), [=](const auto& val){return val<avg;} ); }
#include <iostream> #include <iomanip> using namespace std; double foo( unsigned n ) { double sum=0, a=1; for( unsigned i=0; i!=n; ++i ) { a = 1+1/a; sum += a; } return sum; } int main( void ) { unsigned n; cin >> n; cout << fixed << setprecision(9) << foo(n) << endl; }
[此贴子已经被作者于2020-6-23 08:21编辑过]
#include <iostream> #include <functional> #include <algorithm> using namespace std; int main( void ) { char buf[] = { 'A','A','4','4','3','3','2','2' }; for( ; std::next_permutation(begin(buf),end(buf),std::greater<char>()); ) { auto foo = [=](char ch, size_t interval) { auto a = std::find( begin(buf), end(buf), ch ); auto b = std::find( a+1, end(buf),ch ); return a+interval == b; }; if( foo('A',2) && foo('2',3) && foo('3',4) && foo('4',5) ) break; } cout.write( buf, size(buf) ); }
[此贴子已经被作者于2020-6-23 08:30编辑过]