#2327583

Solution for ITP1_6_B: Finding Missing Cards by motorman

Source Code Status Test Cases
    Policy: public     Reviewed: 3    
00.00 sec    2652 KB    65 lines     1090 bytes    2017-05-20 03:25
#include <cstdio>

using namespace std;

inline int suit_to_id(char c) {
  switch (c) {
    case 'S':
      return 0;
    case 'H':
      return 13;
    case 'C':
      return 26;
    case 'D':
      return 39;
  }
  // should not reach here
  return 0;
}

inline char id_to_suit(int i) {
  switch (i) {
    case 0 ... 12:
      return 'S';
    case 13 ... 25:
      return 'H';
    case 26 ... 38:
      return 'C';
    case 39 ... 51:
      return 'D';
  }
  // should not reach here
  return 'S';
}

int main() {
  // 0..12 => S1..S13
  // 13..25 => H1..H13
  // 26..38 => C1..C13
  // 39..51 => D1..D13
  char bits[8] = {0};

  int n;
  scanf("%d\n", &n);

  char c;
  int x;
  for (int i = 0; i < n; ++i) {
    scanf("%c %d\n", &c, &x);
    const int offset = suit_to_id(c);
    const int bitpos = offset + x - 1;
    bits[bitpos / 8] |= (1 << (bitpos % 8));
  }

  for (int i = 0; i < 52; ++i) {
    int y = 1 << (i % 8);
    if (!(bits[i/8] & y)) {
      const char s = id_to_suit(i);
      const int v = i - suit_to_id(s) + 1;
      printf("%c %d\n", s, v);
    }
  }

  return 0;
}

Compile Error Logs:
You are not authorized to see the message.

Status
Judge: 4/4 C++ CPU: 00.00 sec Memory: 2652 KB Length: 1090 B 2017-05-20 03:25 2017-05-20 03:25
Results for testcases
Case # Verdict CPU Time Memory In Out Case Name
Case #1: : Accepted 00.00 sec 2652 KB
Case #2: : Accepted 00.00 sec 2560 KB
Case #3: : Accepted 00.00 sec 2588 KB
Case #4: : Accepted 00.00 sec 2560 KB
< prev | / | next >  
 
Judge Input #  ( | ) Judge Output #  ( | )


Comments
 
 Under Construction.
 
Categories
 
 
Free Tags