From 7a325e88186dadf75ac44ff63e1ecb8a13f170ef Mon Sep 17 00:00:00 2001 From: Philippe Zwietering Date: Fri, 15 Apr 2022 14:12:34 +0200 Subject: [PATCH] Finished 2 of usaco --- usaco/ch1/beads.cpp | 25 ++++++++++++ usaco/ch1/friday.cpp | 92 ++++++++++++++++++++++++++++++++++++++++++++ usaco/ch1/gift1.cpp | 15 ++++++-- 3 files changed, 128 insertions(+), 4 deletions(-) create mode 100644 usaco/ch1/beads.cpp create mode 100644 usaco/ch1/friday.cpp diff --git a/usaco/ch1/beads.cpp b/usaco/ch1/beads.cpp new file mode 100644 index 0000000..444d581 --- /dev/null +++ b/usaco/ch1/beads.cpp @@ -0,0 +1,25 @@ +/* +ID: philipp17 +PROG: beads +LANG: C++ +*/ +/* LANG can be C++11 or C++14 for those more recent releases */ +#include +#include +#include + +using namespace std; + +int main() { + ofstream fout ("beads.out"); + ifstream fin ("beads.in"); + + int n; + string s; + + fin >> n >> s; + + + + return 0; +} \ No newline at end of file diff --git a/usaco/ch1/friday.cpp b/usaco/ch1/friday.cpp new file mode 100644 index 0000000..fe1498a --- /dev/null +++ b/usaco/ch1/friday.cpp @@ -0,0 +1,92 @@ +/* +ID: philipp17 +PROG: friday +LANG: C++ +*/ +/* LANG can be C++11 or C++14 for those more recent releases */ +#include +#include +#include +#include + +using namespace std; + + +// We start on Monday, and the daylist has to start on Saturday +vector DAY_COUNTER(7, 0); +int CURRENT_DAY = 2; + +bool is_leap(int year){ + if(year % 400 == 0){ + return true; + } else if(year % 100 == 0){ + return false; + } else if(year % 4 == 0){ + return true; + } + return false; +} + +void monthly_routine(int days){ + for(int day = 0; day < days; ++day){ + if(day == 12){ + DAY_COUNTER[CURRENT_DAY] += 1; + // cout << CURRENT_DAY << endl; + } + + CURRENT_DAY = (CURRENT_DAY + 1) % 7; + } +} + +int main() { + ofstream fout ("friday.out"); + ifstream fin ("friday.in"); + + int n; + fin >> n; + + for(int year = 1900; year < 1900 + n; ++year){ + // January + monthly_routine(31); + + // February + monthly_routine(is_leap(year) ? 29 : 28); + + // March + monthly_routine(31); + + // April + monthly_routine(30); + + // May + monthly_routine(31); + + // June + monthly_routine(30); + + // July + monthly_routine(31); + + // August + monthly_routine(31); + + // September + monthly_routine(30); + + // October + monthly_routine(31); + + // November + monthly_routine(30); + + // December + monthly_routine(31); + } + + for(size_t i = 0; i < DAY_COUNTER.size(); ++i){ + fout << DAY_COUNTER[i]; + if(i != DAY_COUNTER.size() - 1) fout << " "; + } fout << endl; + + return 0; +} \ No newline at end of file diff --git a/usaco/ch1/gift1.cpp b/usaco/ch1/gift1.cpp index 4994c6e..1d9165b 100644 --- a/usaco/ch1/gift1.cpp +++ b/usaco/ch1/gift1.cpp @@ -24,7 +24,6 @@ int main() { map index_to_name; vector bank(np, 0); - vector spendings(np, 0); for(int i = 0; i < np; ++i){ string s; @@ -40,15 +39,23 @@ int main() { fin >> name >> money >> ng; + // cout << name << " " << money << " " << ng << endl; + if(ng == 0){ continue; } vector receivers(ng); - for(int j = 0; j < ng; ++i){ + // cout << ng << endl; + + for(int j = 0; j < ng; ++j){ fin >> receivers[j]; } + // for(string s: receivers){ + // cout << s << " "; + // } + if(money == 0){ continue; } @@ -57,13 +64,13 @@ int main() { for(const string &receiver : receivers){ bank[names_to_index[receiver]] += money_per_person; - spendings[names_to_index[receiver]] -= money_per_person; } + bank[names_to_index[name]] -= money_per_person * ng; } // Printing the output for(int i = 0; i < np; ++i){ - fout << index_to_name[i] << bank[i] - spendings[i] << endl; + fout << index_to_name[i] << " " << bank[i] << endl; } return 0;