2022-10-14 09:27:47 +01:00
|
|
|
#include <iostream>
|
2022-10-28 10:11:47 +01:00
|
|
|
#include <list>
|
2022-11-04 11:58:21 +00:00
|
|
|
#include <algorithm>
|
2022-10-28 12:18:30 +01:00
|
|
|
#include <map>
|
2022-10-19 09:33:42 +01:00
|
|
|
#include <iomanip>
|
2022-10-14 09:27:47 +01:00
|
|
|
|
|
|
|
using string = std::string;
|
2022-11-04 12:22:52 +00:00
|
|
|
using ilist = std::list<int>;
|
2022-10-14 09:27:47 +01:00
|
|
|
|
2022-10-28 09:43:51 +01:00
|
|
|
//Place in header!
|
2022-10-19 09:33:42 +01:00
|
|
|
template <typename T>
|
|
|
|
void printm(T m){
|
2022-10-14 09:27:47 +01:00
|
|
|
std::cout << m;
|
|
|
|
}
|
|
|
|
|
2022-10-19 09:33:42 +01:00
|
|
|
template <typename T>
|
|
|
|
void printlm(T m){
|
2022-10-14 09:27:47 +01:00
|
|
|
printm(m);
|
|
|
|
printm("\n");
|
|
|
|
}
|
|
|
|
|
2022-10-28 09:43:51 +01:00
|
|
|
int prompti(string,bool*);
|
2022-11-04 12:22:52 +00:00
|
|
|
int prompti(string,bool*);
|
2022-10-28 12:18:30 +01:00
|
|
|
string prompts(string,bool*);
|
2022-10-19 09:33:42 +01:00
|
|
|
|
|
|
|
int main() {
|
2022-11-04 12:30:49 +00:00
|
|
|
printlm("Get the number of 0s before 1 from:");
|
2022-11-04 12:22:52 +00:00
|
|
|
bool s {};
|
|
|
|
ilist lst {};
|
|
|
|
do {
|
|
|
|
auto v = prompti("Enter an integer: ", &s);
|
|
|
|
if (s) {
|
|
|
|
lst.push_back(v);
|
2022-11-04 11:58:21 +00:00
|
|
|
}
|
2022-11-04 12:22:52 +00:00
|
|
|
} while (s);
|
2022-11-04 12:30:49 +00:00
|
|
|
printm("Number of 0s before 1: ");
|
2022-11-04 12:34:31 +00:00
|
|
|
const auto the1 = find(lst.cbegin(),lst.cend(),1);
|
|
|
|
printlm(count(lst.cbegin(),the1, 0));
|
2022-10-19 09:33:42 +01:00
|
|
|
return 0;
|
2022-10-14 09:27:47 +01:00
|
|
|
}
|
|
|
|
|
2022-10-28 09:43:51 +01:00
|
|
|
int prompti(string message, bool *status) {
|
|
|
|
int tr {};
|
2022-10-19 09:33:42 +01:00
|
|
|
*status = false;
|
2022-10-14 09:27:47 +01:00
|
|
|
std::cout << message;
|
2022-10-19 09:33:42 +01:00
|
|
|
if (!(std::cin >> tr)){
|
2022-10-14 09:27:47 +01:00
|
|
|
std::cin.clear();
|
|
|
|
std::cin.ignore();
|
2022-10-19 09:33:42 +01:00
|
|
|
return 0;
|
2022-10-14 09:27:47 +01:00
|
|
|
}
|
2022-10-19 09:33:42 +01:00
|
|
|
*status = true;
|
2022-10-14 09:27:47 +01:00
|
|
|
return tr;
|
|
|
|
}
|
2022-10-19 09:33:42 +01:00
|
|
|
|
2022-10-28 10:11:47 +01:00
|
|
|
double promptd(string message, bool *status) {
|
|
|
|
double tr {};
|
|
|
|
*status = false;
|
|
|
|
std::cout << message;
|
|
|
|
if (!(std::cin >> tr)){
|
|
|
|
std::cin.clear();
|
|
|
|
std::cin.ignore();
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
*status = true;
|
|
|
|
return tr;
|
|
|
|
}
|
|
|
|
|
2022-10-28 12:18:30 +01:00
|
|
|
string prompts(string message, bool *status) {
|
|
|
|
string tr {""};
|
|
|
|
*status = false;
|
|
|
|
std::cout << message;
|
|
|
|
if (!(std::cin >> tr)){
|
|
|
|
std::cin.clear();
|
|
|
|
std::cin.ignore();
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
*status = true;
|
|
|
|
return tr;
|
2022-10-28 10:11:47 +01:00
|
|
|
}
|