Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define _USE_MATH_DEFINES
  3.  
  4. #include "bits/stdc++.h"
  5. #define REP(i,a,b) for(int i=a;i<b;++i)
  6. #define rep(i,n) REP(i,0,n)
  7. typedef long long ll;
  8. typedef unsigned long long ull;
  9. typedef long double ld;
  10. #define ALL(a) begin(a),end(a)
  11. #define ifnot(a) if(not (a))
  12. #define dump(x) cerr << #x << " = " << (x) << endl
  13. using namespace std;
  14.  
  15. // #define int ll
  16. #ifdef _MSC_VER
  17. const bool test = true;
  18. #else
  19. const bool test = false;
  20. #endif
  21.  
  22. int dx[] = { 0,1,0,-1 };
  23. int dy[] = { 1,0,-1,0 };
  24. #define INF (1 << 28)
  25. ull mod = (int)1e9 + 7;
  26. //.....................
  27. const int MAX = (int)2e5 + 5;
  28.  
  29. struct Person {
  30. string name;
  31. int HP;
  32. int money;
  33. Person(string name) : name(name) {
  34. HP = 100;
  35. money = 0;
  36. };
  37. };
  38.  
  39. struct People {
  40. vector<Person> people;
  41. Person operator [](int id) { return people[id]; };
  42. void add(string name);
  43. void print();
  44. void death(string name);
  45. void earn(string name);
  46. void attack(int n);
  47. };
  48.  
  49. void People::add(string name) {
  50. Person person(name);
  51. people.push_back(person);
  52. cout << name + " : " + "ぽきたw" << endl;
  53. }
  54.  
  55. void People::print() {
  56. cout << "people" << endl;
  57. cout << "------" << endl;
  58. cout << setw(8) << left << "name "
  59. << setw(8) << left << "HP "
  60. << setw(8) << left << "money "
  61. << endl;
  62. cout << "------" << endl;
  63. for (auto person : people) {
  64. cout << setw(8) << left << person.name + " "
  65. << setw(8) << left << to_string(person.HP) + " "
  66. << setw(8) << left << to_string(person.money) + "$ "
  67. << endl;
  68. }
  69. cout << "------" << endl;
  70. cout << endl;
  71. }
  72.  
  73. void People::death(string name) {
  74. auto itr = people.begin();
  75. for (; itr != people.end(); ) {
  76. if (itr->name == name) {
  77. itr = people.erase(itr);
  78. cout << name + " : " + "ぽやしみ~" << endl;
  79. }
  80. else itr++;
  81. }
  82. }
  83.  
  84. void People::earn(string name) {
  85. for (auto& p : people) {
  86. int n = 1 << (rand() % 25);
  87. if (p.money > (int)1e6 || rand() % 100 > 70) {
  88. n *= -1;
  89. }
  90. if (p.name == name) {
  91. p.money += n;
  92. cout << setw(8) << left << p.name
  93. << setw(8) << left << showpos << n << "$"
  94. << endl;
  95. }
  96. }
  97. }
  98.  
  99. void People::attack(int n) {
  100. for (auto& person : people) {
  101. int n = rand() % 30;
  102. cout << setw(8) << left << person.name
  103. << setw(8) << left << showpos << -n
  104. << endl;
  105. person.HP -= n;
  106. }
  107. }
  108.  
  109. void op_exe(People& people, string& op, string& name) {
  110. if (op == "add" || op == "a") people.add(name);
  111. else if (op == "death" || op == "d") people.death(name);
  112. else if (op == "earn" || op == "e") people.earn(name);
  113. else if (op == "attack" || op == "e") people.attack(stoi(name));
  114. else cout << "op \"" + op + "\" " + "is undefined" << endl;
  115. }
  116.  
  117. int main() {
  118. srand(time(NULL));
  119. People people;
  120. while (1) {
  121. people.print();
  122. string op;
  123. string name;
  124. cin >> op >> name;
  125. if (op == "loop" || op == "l") {
  126. int n = stoi(name);
  127. cin >> op >> name;
  128. rep(i, n) {
  129. op_exe(people, op, name);
  130. }
  131. }
  132. else op_exe(people, op, name);
  133. }
  134. return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement