Advertisement
Gortkab

A Chessboard Game

Oct 17th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. vector<string> split_string(string);
  6.  
  7. // Complete the chessboardGame function below.
  8. string chessboardGame(int x, int y) {
  9.     if ((x%4 == 1 || x%4 == 2) && (y%4 == 1 || y%4 ==2)) {
  10.         return "Second";
  11.     } else {
  12.         return "First";
  13.     }
  14.  
  15. }
  16.  
  17. int main()
  18. {
  19.     ofstream fout(getenv("OUTPUT_PATH"));
  20.  
  21.     int t;
  22.     cin >> t;
  23.     cin.ignore(numeric_limits<streamsize>::max(), '\n');
  24.  
  25.     for (int t_itr = 0; t_itr < t; t_itr++) {
  26.         string xy_temp;
  27.         getline(cin, xy_temp);
  28.  
  29.         vector<string> xy = split_string(xy_temp);
  30.  
  31.         int x = stoi(xy[0]);
  32.  
  33.         int y = stoi(xy[1]);
  34.  
  35.         string result = chessboardGame(x, y);
  36.  
  37.         fout << result << "\n";
  38.     }
  39.  
  40.     fout.close();
  41.  
  42.     return 0;
  43. }
  44.  
  45. vector<string> split_string(string input_string) {
  46.     string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) {
  47.         return x == y and x == ' ';
  48.     });
  49.  
  50.     input_string.erase(new_end, input_string.end());
  51.  
  52.     while (input_string[input_string.length() - 1] == ' ') {
  53.         input_string.pop_back();
  54.     }
  55.  
  56.     vector<string> splits;
  57.     char delimiter = ' ';
  58.  
  59.     size_t i = 0;
  60.     size_t pos = input_string.find(delimiter);
  61.  
  62.     while (pos != string::npos) {
  63.         splits.push_back(input_string.substr(i, pos - i));
  64.  
  65.         i = pos + 1;
  66.         pos = input_string.find(delimiter, i);
  67.     }
  68.  
  69.     splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1));
  70.  
  71.     return splits;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement