fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int countSheep(const vector<bool>& sheep) {
  6. int count = 0;
  7.  
  8. for (bool s : sheep) {
  9. if (s == true) {
  10. count++;
  11. }
  12. }
  13. return count;
  14. }
  15.  
  16. int main() {
  17. vector<bool> sheep = {
  18. true, true, true, false,
  19. true, true, true, true,
  20. true, false, true, false,
  21. true, false, false, true,
  22. true, true, true, true,
  23. false, false, true, true
  24. };
  25.  
  26. cout << countSheep(sheep); // Output: 17
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
17