#include <algorithm>
template< class T >
void Swap( T& a, T& b ) { std::swap( a, b ); }
Describe(Tests)
{
It(Swaps)
{
int a = 1, b = 2;
bool c = true, d = false;
double e = 3.14, f = 6.28;
Swap( a, b );
Swap( c, d );
Swap( e, f );
Assert::That( a, Equals(2));
Assert::That( b, Equals(1));
Assert::That( c, Equals(false));
Assert::That( d, Equals(true));
Assert::That( e, Equals(6.28));
Assert::That( f, Equals(3.14));
}
};
#include <numeric> int stray(std::vector<int> numbers) { int sum = std::accumulate( numbers.begin(), numbers.end(), 0); int sample = numbers[0] == numbers[1] ? numbers[1] : numbers[2]; return sum % sample + ( numbers.size() == (sum / sample) ? sample : 0 ); }
int stray(std::vector<int> numbers) {for(auto n = numbers.begin(); n != numbers.end(); ++n ){if (*n != numbers[0]) {if (*n != *(n + 1))return *n;elsereturn numbers[0];}}};- #include <numeric>
- int stray(std::vector<int> numbers)
- {
- int sum = std::accumulate( numbers.begin(), numbers.end(), 0);
- int sample = numbers[0] == numbers[1] ? numbers[1] : numbers[2];
- return sum % sample + ( numbers.size() == (sum / sample) ? sample : 0 );
- }
// TODO: Replace examples and use TDD development by writing your own tests Describe(array) { It(should_do_something) { Assert::That(stray({0,1,1,1}), Equals(0)); Assert::That(stray({2,2,2,2,3}), Equals(3)); Assert::That(stray({3,3,4,3,3,3}), Equals(4)); } };
- // TODO: Replace examples and use TDD development by writing your own tests
- Describe(array)
- {
- It(should_do_something)
- {
- Assert::That(stray({0,1,1,1}), Equals(0));
- Assert::That(stray({2,2,2,2,3}), Equals(3));
- Assert::That(stray({3,3,4,3,3,3}), Equals(4));
- }
- };
bool Or ( bool a, bool b ){ return a | b; } bool Xor ( bool a, bool b ){ return a ^ b; } bool And ( bool a, bool b ){ return a & b; }
bool Or(bool a, bool b){return a ? true : (b ? true : false);}bool Xor(bool a, bool b){return a ? (b ? false : true) : (b ? true : false);}bool And(bool a, bool b){return a ? (b ? true : false) : false;}- bool Or ( bool a, bool b ){ return a | b; }
- bool Xor ( bool a, bool b ){ return a ^ b; }
- bool And ( bool a, bool b ){ return a & b; }