fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. #include <string.h>
  5.  
  6. /* トランプの枚数 */
  7. #define N 52
  8.  
  9. /* トランプ構造体の定義 */
  10. typedef struct playingcard {
  11. char suit;
  12. int number;
  13. bool val;
  14. } playingcard_t;
  15.  
  16. int main(void) {
  17. playingcard_t deck[N];
  18. char* suit = "SHCD";
  19. int n = 0;
  20. /* トランプを詰めたデッキを生成する */
  21. for (int i = 0; i < 4; i++) {
  22. for (int j = 1; j < 14; j++) {
  23. deck[n].suit = suit[i];
  24. deck[n].number = j;
  25. deck[n].val = true;
  26. n++;
  27. }
  28. }
  29. /* 入力処理 */
  30. char buffer[5];
  31. scanf("%4s%*[^\n]", buffer);
  32. n = strtol(buffer, NULL, 10);
  33. if ((n > 52) || (n < 1)) {
  34. return EXIT_FAILURE;
  35. }
  36. char *token;
  37. /* バッファを空白でトークンに分ける */
  38. for (int i = 0; i < n; i++) {
  39. scanf("%4[^\n]%*[^\n]", buffer);
  40. token = strtok(buffer, " ");
  41. suit = token;
  42. token = strtok(NULL, " ");
  43. /* デッキ内のトランプとトークンが一致した時、トランプ構造体のブール値を false にする */
  44. for (int j = 0; j < N; j++) {
  45. if ((deck[j].suit == suit[0]) && (deck[j].number == strtol(token, NULL, 10))) {
  46. deck[j].val = false;
  47. break;
  48. }
  49. }
  50. }
  51. /* デッキのトランプ構造体のブール値が真の時のみ出力する */
  52. for (int i = 0; i < N; i++) {
  53. if (deck[i].val) {
  54. printf("%c %d\n", deck[i].suit, deck[i].number);
  55. }
  56. }
  57. return EXIT_SUCCESS;
  58. }
  59.  
Runtime error #stdin #stdout 0.01s 5520KB
stdin
Standard input is empty
stdout
Standard output is empty