Set up base directory for usaco and started on gift1
This commit is contained in:
22
usaco/base.cpp
Normal file
22
usaco/base.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
ID: philipp17
|
||||
PROG:
|
||||
LANG: C++
|
||||
*/
|
||||
/* LANG can be C++11 or C++14 for those more recent releases */
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
ofstream fout (".out");
|
||||
ifstream fin (".in");
|
||||
|
||||
string a, b;
|
||||
|
||||
fin >> a >> b;
|
||||
|
||||
return 0;
|
||||
}
|
||||
70
usaco/ch1/gift1.cpp
Normal file
70
usaco/ch1/gift1.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
ID: philipp17
|
||||
PROG: gift1
|
||||
LANG: C++
|
||||
*/
|
||||
/* LANG can be C++11 or C++14 for those more recent releases */
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main() {
|
||||
ofstream fout ("gift1.out");
|
||||
ifstream fin ("gift1.in");
|
||||
|
||||
int np;
|
||||
fin >> np;
|
||||
|
||||
map<string, int> names_to_index;
|
||||
map<int, string> index_to_name;
|
||||
|
||||
vector<int> bank(np, 0);
|
||||
vector<int> spendings(np, 0);
|
||||
|
||||
for(int i = 0; i < np; ++i){
|
||||
string s;
|
||||
fin >> s;
|
||||
|
||||
names_to_index[s] = i;
|
||||
index_to_name[i] = s;
|
||||
}
|
||||
|
||||
for(int i = 0; i < np; ++i){
|
||||
string name;
|
||||
int money, ng;
|
||||
|
||||
fin >> name >> money >> ng;
|
||||
|
||||
if(ng == 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
vector<string> receivers(ng);
|
||||
for(int j = 0; j < ng; ++i){
|
||||
fin >> receivers[j];
|
||||
}
|
||||
|
||||
if(money == 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
int money_per_person = money / ng;
|
||||
|
||||
for(const string &receiver : receivers){
|
||||
bank[names_to_index[receiver]] += money_per_person;
|
||||
spendings[names_to_index[receiver]] -= money_per_person;
|
||||
}
|
||||
}
|
||||
|
||||
// Printing the output
|
||||
for(int i = 0; i < np; ++i){
|
||||
fout << index_to_name[i] << bank[i] - spendings[i] << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user