Skip to content

Commit

Permalink
Update ex14_43.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooophy authored and pezy committed May 26, 2015
1 parent 83bb7b7 commit 0b876b4
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions ch14/ex14_43.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* @file main.cpp
* @author XDXX
* @author XDXX, Yue Wang
* @date 5/24/2015
* @remark This code is for the exercises from C++ Primer 5th Edition
* @note
Expand All @@ -12,24 +12,19 @@
//!

#include <iostream>
#include <vector>
#include <string>
#include <functional>
#include <algorithm>

int main()
{
std::vector<int> vec = {1, 2, 3, 4};
auto data = { 2, 3, 4, 5 };
int input;
std::cin >> input;
std::modulus<int> mod;
int num;
std::cin >> num;
std::string result = "yes";
for (const auto i : vec) {
if (mod(num, i)) {
result = "no";
break;
}
}
auto predicator = [&](int i){ return 0 == mod(input, i); };
auto is_divisible = std::any_of(data.begin(), data.end(), predicator);
std::cout << (is_divisible ? "Yes!" : "No!") << std::endl;

std::cout << result << std::endl;
return 0;
}
}

0 comments on commit 0b876b4

Please sign in to comment.