number of 0s before 1 (count_if)
This commit is contained in:
parent
413ca3faef
commit
b8eff8c9ea
20
main.cpp
20
main.cpp
@ -22,10 +22,10 @@ void printlm(T m){
|
|||||||
int prompti(string,bool*);
|
int prompti(string,bool*);
|
||||||
int prompti(string,bool*);
|
int prompti(string,bool*);
|
||||||
string prompts(string,bool*);
|
string prompts(string,bool*);
|
||||||
bool isneg(int);
|
bool num0b1(int);
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
printlm("Get the number of negatives from::");
|
printlm("Get the number of 0s before 1 from:");
|
||||||
bool s {};
|
bool s {};
|
||||||
ilist lst {};
|
ilist lst {};
|
||||||
do {
|
do {
|
||||||
@ -34,10 +34,8 @@ int main() {
|
|||||||
lst.push_back(v);
|
lst.push_back(v);
|
||||||
}
|
}
|
||||||
} while (s);
|
} while (s);
|
||||||
printm("Number of negatives (Defined): ");
|
printm("Number of 0s before 1: ");
|
||||||
printlm(count_if(lst.cbegin(), lst.cend(), isneg));
|
printlm(count_if(lst.cbegin(),lst.cend(), num0b1));
|
||||||
printm("Number of negatives (Lambda): ");
|
|
||||||
printlm(count_if(lst.cbegin(), lst.cend(), [] (int x) { return x < 0;}));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +78,12 @@ string prompts(string message, bool *status) {
|
|||||||
return tr;
|
return tr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isneg(int x) {
|
bool num0b1(int x) {
|
||||||
return x < 0;
|
static bool has1 {};
|
||||||
|
if (x == 1) has1 = true;
|
||||||
|
if (has1 || x != 0) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user