fork download
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <bits/stdc++.h>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. #define ll long long
  7. #define ld long double
  8.  
  9. int main() {
  10. // your code goes here
  11.  
  12. string SM, SA, SR;
  13. cin >> SM >> SA >> SR;
  14.  
  15. queue<char> qm, qa, qr;
  16.  
  17. for (char c : SM) qm.push(c);
  18. for (char c : SA) qa.push(c);
  19. for (char c : SR) qr.push(c);
  20.  
  21. char current = 'm';
  22.  
  23. while (true)
  24. {
  25. if (current == 'm')
  26. {
  27. if (qm.empty())
  28. {
  29. cout << "M\n";
  30. break;
  31. }
  32. current = qm.front();
  33. qm.pop();
  34. }
  35. else if (current == 'a')
  36. {
  37. if (qa.empty())
  38. {
  39. cout << "A\n";
  40. break;
  41. }
  42. current = qa.front();
  43. qa.pop();
  44. }
  45. else
  46. {
  47. if (qr.empty())
  48. {
  49. cout << "R\n";
  50. break;
  51. }
  52. current = qr.front();
  53. qr.pop();
  54. }
  55. }
  56. return 0;
  57. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
M