use find to get the 1 and count 0s to that position
This commit is contained in:
parent
b8eff8c9ea
commit
35253444f4
14
main.cpp
14
main.cpp
@ -22,7 +22,6 @@ 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 num0b1(int);
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
printlm("Get the number of 0s before 1 from:");
|
printlm("Get the number of 0s before 1 from:");
|
||||||
@ -35,7 +34,8 @@ int main() {
|
|||||||
}
|
}
|
||||||
} while (s);
|
} while (s);
|
||||||
printm("Number of 0s before 1: ");
|
printm("Number of 0s before 1: ");
|
||||||
printlm(count_if(lst.cbegin(),lst.cend(), num0b1));
|
const auto the1 = find(lst.cbegin(),lst.cend(),1);
|
||||||
|
printlm(count(lst.cbegin(),the1, 0));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,13 +77,3 @@ string prompts(string message, bool *status) {
|
|||||||
*status = true;
|
*status = true;
|
||||||
return tr;
|
return tr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool num0b1(int x) {
|
|
||||||
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