fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. class game
  6. {
  7. int m, n;
  8.  
  9. bool play( div_t d )
  10. {
  11. if ( d.rem == 0 or d.quot > 1 )
  12. return false;
  13.  
  14. n = m, m = d.rem;
  15.  
  16. return true;
  17. }
  18.  
  19. public:
  20.  
  21. bool new_game()
  22. {
  23. cin >> m >> n;
  24.  
  25. if ( m > n )
  26. swap( m, n );
  27.  
  28. return m > 0;
  29. }
  30.  
  31. void solve()
  32. {
  33. int p = 0; const string winner[] = { "Stan", "Ollie" };
  34.  
  35. while( play( div( n, m ) ) )
  36. p ^= 1;
  37.  
  38. cout << winner[ p ] << ' ' << "wins" << '\n';
  39. }
  40. };
  41.  
  42. int main()
  43. {
  44. ios_base::sync_with_stdio( 0 ), cin.tie( 0 ), cout.tie( 0 );
  45.  
  46. for( game g; g.new_game(); g.solve() );
  47. }
  48.  
Success #stdin #stdout 0s 15240KB
stdin
34 12
15 24
0 0
stdout
Stan wins
Ollie wins