usaco-camp

Short, concise solutions for problems from the USACO camp

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
#include <iostream>

/*
 * You need to implement the following functions:
 */

void add_friend(std::string cow1, std::string cow2, int timestamp);
bool check_friend(std::string cow1, std::string cow2, int timestamp);
int get_number_of_friends(std::string cow, int timestamp);

// Commands have the following format:
// A c1 c2 t
//  - Calls "add"friend" on cows "c1" and "c2" at timestamp t. You are
//    guaranteed that successive calls to A will have increasing values of t.
// C c1 c2 t
//  - Calls "check_friend" on cows "c1" and "c2" at timestamp t.
// N c t
//  - Calls "get_number_of_friends" on cow "c" at timestamp "t".

// You don't need to read or understand any of the code below,
// but it may be helpful.

int main() {
  int num_commands;
  std::cin >> num_commands;

  for (int i = 0; i < num_commands; ++i) {
    std::string command_type;
    std::cin >> command_type;

    if (command_type == "A") {
      std::string cow1, cow2;
      int timestamp;
      std::cin >> cow1 >> cow2 >> timestamp;

      add_friend(cow1, cow2, timestamp);
    } else if (command_type == "C") {
      std::string cow1, cow2;
      int timestamp;
      std::cin >> cow1 >> cow2 >> timestamp;

      std::string responses[] = {"FALSE", "TRUE"};
      std::cout << responses[check_friend(cow1, cow2, timestamp)] << std::endl;
    } else if (command_type == "N") {
      std::string cow;
      int timestamp;
      std::cin >> cow >> timestamp;

      std::cout << get_number_of_friends(cow, timestamp) << std::endl;
    } else {
      std::cout << "Invalid command type: " << command_type << std::endl;
      exit(1);
    }
  }
}