1
0

use find to get the 1 and count 0s to that position

This commit is contained in:
Captain ALM 2022-11-04 12:34:31 +00:00
parent b8eff8c9ea
commit 35253444f4
3 changed files with 2 additions and 12 deletions

View File

@ -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;
}
}

BIN
main.o

Binary file not shown.

BIN
t

Binary file not shown.