1
0

process comma deliminated list into entries

This commit is contained in:
Captain ALM 2022-11-04 12:50:06 +00:00
parent 35253444f4
commit 1da7074bfc
3 changed files with 16 additions and 11 deletions

View File

@ -5,7 +5,7 @@
#include <iomanip> #include <iomanip>
using string = std::string; using string = std::string;
using ilist = std::list<int>; using slist = std::list<string>;
//Place in header! //Place in header!
template <typename T> template <typename T>
@ -24,18 +24,23 @@ int prompti(string,bool*);
string prompts(string,bool*); string prompts(string,bool*);
int main() { int main() {
printlm("Get the number of 0s before 1 from:"); printlm("Parse comma deliminated list:");
bool s {}; bool s {};
ilist lst {}; slist lst {};
auto v = prompts("Enter the string: ", &s);
if (!s) {
printlm("Error, No Data!");
return -1;
}
auto comma = find(v.cbegin(),v.cend(),',');
lst.push_back(string(v.cbegin(),comma));
do { do {
auto v = prompti("Enter an integer: ", &s); auto start = ++comma;
if (s) { comma = find(start,v.cend(),',');
lst.push_back(v); lst.push_back(string(start, comma));
} } while(comma != v.cend());
} while (s); printlm("All entries:");
printm("Number of 0s before 1: "); for (const auto c : lst) printlm(c);
const auto the1 = find(lst.cbegin(),lst.cend(),1);
printlm(count(lst.cbegin(),the1, 0));
return 0; return 0;
} }

BIN
main.o

Binary file not shown.

BIN
t

Binary file not shown.