algorithms

Algorithm implementations
git clone git://git.laack.co/algorithms.git
Log | Files | Refs | README

commit 7d16114abe60e91e112ae93ba5938ef0a91b2d10
parent b63e5a3222ab104556e607146d9bd4c63bd2f2c9
Author: Andrew Laack <andrew@laack.co>
Date:   Tue, 17 Nov 2026 09:53:58 -0600

two more 1000s in c++

Diffstat:
Acomp/bar/ex1.in | 6++++++
Acomp/bar/ex2.in | 0
Acomp/bar/main.cpp | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acomp/bar/thoughts.txt | 0
Acomp/seats/ex1.in | 11+++++++++++
Acomp/seats/ex2.in | 0
Acomp/seats/main.cpp | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acomp/seats/thoughts.txt | 0
8 files changed, 134 insertions(+), 0 deletions(-)

diff --git a/comp/bar/ex1.in b/comp/bar/ex1.in @@ -0,0 +1,6 @@ +5 +18 +VODKA +COKE +19 +17 diff --git a/comp/bar/ex2.in b/comp/bar/ex2.in diff --git a/comp/bar/main.cpp b/comp/bar/main.cpp @@ -0,0 +1,59 @@ +#include <iostream> +#include <vector> +#include <unordered_set> +#include <unordered_map> +#include <algorithm> +#include <queue> + +#define ll long long + +using namespace std; + +// no under 18 +// n ppl sitting there +// knows either the age or drink they're having +// check means learn both + +// what minimal number of people should be asked to make sure no one under 18 is drinking + + +int main() { + + int ppl; + cin >> ppl; + + unordered_set<string> drinks {}; + drinks.insert("ABSINTH"); + drinks.insert("BEER"); + drinks.insert("BRANDY"); + drinks.insert("CHAMPAGNE"); + drinks.insert("GIN"); + drinks.insert("RUM"); + drinks.insert("SAKE"); + drinks.insert("TEQUILA"); + drinks.insert("VODKA"); + drinks.insert("WHISKEY"); + drinks.insert("WINE"); + + ll res = 0; + for(int z = 0; z < ppl; ++z) { + string current; + cin >> current; + + if(drinks.contains(current)) { + res += 1; + continue; + } + + try { + int age = stoi(current); + if(age < 18) { + res += 1; + } + } catch (...) { + continue; + } + + } + cout << res << endl; +} diff --git a/comp/bar/thoughts.txt b/comp/bar/thoughts.txt diff --git a/comp/seats/ex1.in b/comp/seats/ex1.in @@ -0,0 +1,11 @@ +5 +1 +0 +3 +000 +5 +00000 +6 +100101 +13 +0000100001000 diff --git a/comp/seats/ex2.in b/comp/seats/ex2.in diff --git a/comp/seats/main.cpp b/comp/seats/main.cpp @@ -0,0 +1,58 @@ +#include <iostream> +#include <vector> +#include <unordered_set> +#include <unordered_map> +#include <algorithm> +#include <queue> + +#define ll long long + +// n seats +// no sitting next to each other +// binary string for occupancy + +// Your task is to calculate the minimum total number of students seated when it is impossible to seat anyone else in the row + + +using namespace std; + +int main() { + + int testCases; + cin >> testCases; + + for(int z = 0; z < testCases; ++z) { + int n; + string current; + cin >> n; + cin >> current; + + ll sum = 0; + for(int i = 0; i < current.size(); ++i) { + if(current[i] == '1') + sum += 1; + } + + + for(int i = 0; i < current.size(); ++i) { + if(current[i] == '1') { + continue; + } + if(i > 0 && current[i-1] == '1') { + continue; + } + if(i + 1 < current.size() && current[i+1] == '1') { + continue; + } + if(i + 1 < current.size() && !(i + 2 < current.size() && current[i+2] == '1')) { + current[i+1] = '1'; + } + else { + current[i] = '1'; + } + sum += 1; + } + + cout << sum << endl; + } +} diff --git a/comp/seats/thoughts.txt b/comp/seats/thoughts.txt