UVa12247 Jollo

以下のコードは他の人の解答を参考にした。

int ps[3], pr[2], now[3];
bool cards[53];

int main() {
  while(1) {
    memset(cards, 0, sizeof cards);
    for(int i=0; i<3; i++) cin >> ps[i], cards[ps[i]] = true;
    for(int i=0; i<2; i++) cin >> pr[i], cards[pr[i]] = true;
    if(!ps[0]) break;
    sort(ps, ps+3);
    int ans = -1;
    for(int i=52; i>=1; i--) {
      if(cards[i]) continue;
      now[0] = pr[0], now[1] = pr[1], now[2] = i;
      sort(now, now+3);
      if(now[0] > ps[1] || now[1] > ps[2]) {
        ans = i;
      }
    }
    cout << ans << endl;
  }
}