Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define _USE_MATH_DEFINES
- #include "bits/stdc++.h"
- #define REP(i,a,b) for(int i=a;i<b;++i)
- #define rep(i,n) REP(i,0,n)
- typedef long long ll;
- typedef unsigned long long ull;
- typedef long double ld;
- #define ALL(a) begin(a),end(a)
- #define ifnot(a) if(not (a))
- #define dump(x) cerr << #x << " = " << (x) << endl
- using namespace std;
- // #define int ll
- #ifdef _MSC_VER
- const bool test = true;
- #else
- const bool test = false;
- #endif
- int dx[] = { 0,1,0,-1 };
- int dy[] = { 1,0,-1,0 };
- #define INF (1 << 28)
- ull mod = (int)1e9 + 7;
- //.....................
- const int MAX = (int)2e5 + 5;
- struct Person {
- string name;
- int HP;
- int money;
- Person(string name) : name(name) {
- HP = 100;
- money = 0;
- };
- };
- struct People {
- vector<Person> people;
- Person operator [](int id) { return people[id]; };
- void add(string name);
- void print();
- void death(string name);
- void earn(string name);
- void attack(int n);
- };
- void People::add(string name) {
- Person person(name);
- people.push_back(person);
- cout << name + " : " + "ぽきたw" << endl;
- }
- void People::print() {
- cout << "people" << endl;
- cout << "------" << endl;
- cout << setw(8) << left << "name "
- << setw(8) << left << "HP "
- << setw(8) << left << "money "
- << endl;
- cout << "------" << endl;
- for (auto person : people) {
- cout << setw(8) << left << person.name + " "
- << setw(8) << left << to_string(person.HP) + " "
- << setw(8) << left << to_string(person.money) + "$ "
- << endl;
- }
- cout << "------" << endl;
- cout << endl;
- }
- void People::death(string name) {
- auto itr = people.begin();
- for (; itr != people.end(); ) {
- if (itr->name == name) {
- itr = people.erase(itr);
- cout << name + " : " + "ぽやしみ~" << endl;
- }
- else itr++;
- }
- }
- void People::earn(string name) {
- for (auto& p : people) {
- int n = 1 << (rand() % 25);
- if (p.money > (int)1e6 || rand() % 100 > 70) {
- n *= -1;
- }
- if (p.name == name) {
- p.money += n;
- cout << setw(8) << left << p.name
- << setw(8) << left << showpos << n << "$"
- << endl;
- }
- }
- }
- void People::attack(int n) {
- for (auto& person : people) {
- int n = rand() % 30;
- cout << setw(8) << left << person.name
- << setw(8) << left << showpos << -n
- << endl;
- person.HP -= n;
- }
- }
- void op_exe(People& people, string& op, string& name) {
- if (op == "add" || op == "a") people.add(name);
- else if (op == "death" || op == "d") people.death(name);
- else if (op == "earn" || op == "e") people.earn(name);
- else if (op == "attack" || op == "e") people.attack(stoi(name));
- else cout << "op \"" + op + "\" " + "is undefined" << endl;
- }
- int main() {
- srand(time(NULL));
- People people;
- while (1) {
- people.print();
- string op;
- string name;
- cin >> op >> name;
- if (op == "loop" || op == "l") {
- int n = stoi(name);
- cin >> op >> name;
- rep(i, n) {
- op_exe(people, op, name);
- }
- }
- else op_exe(people, op, name);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement