process comma deliminated list into entries
This commit is contained in:
parent
35253444f4
commit
1da7074bfc
27
main.cpp
27
main.cpp
@ -5,7 +5,7 @@
|
||||
#include <iomanip>
|
||||
|
||||
using string = std::string;
|
||||
using ilist = std::list<int>;
|
||||
using slist = std::list<string>;
|
||||
|
||||
//Place in header!
|
||||
template <typename T>
|
||||
@ -24,18 +24,23 @@ int prompti(string,bool*);
|
||||
string prompts(string,bool*);
|
||||
|
||||
int main() {
|
||||
printlm("Get the number of 0s before 1 from:");
|
||||
printlm("Parse comma deliminated list:");
|
||||
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 {
|
||||
auto v = prompti("Enter an integer: ", &s);
|
||||
if (s) {
|
||||
lst.push_back(v);
|
||||
}
|
||||
} while (s);
|
||||
printm("Number of 0s before 1: ");
|
||||
const auto the1 = find(lst.cbegin(),lst.cend(),1);
|
||||
printlm(count(lst.cbegin(),the1, 0));
|
||||
auto start = ++comma;
|
||||
comma = find(start,v.cend(),',');
|
||||
lst.push_back(string(start, comma));
|
||||
} while(comma != v.cend());
|
||||
printlm("All entries:");
|
||||
for (const auto c : lst) printlm(c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user