Functions and Recursions – Strings – Problem #2

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: medium

Problem Statement

In this problem you will rearrange an input shuffle of playing cards in a definite order. You might know that playing cards have 4 suits, each having 13 cards with unique numbers. The ordered suits are ♣ Clubs (C), ♦ Diamonds (D), ♥ Hearts (H), and ♠ Spades (S), and the ordered numbers are 2,3,......,9,J,Q,K,A. (10 is not considered for this problem.) So, in total we have 48 cards, each being uniquely identified by its suit and number. For your code, proceed as follows.  Define a global structure card that can store the ID (= suit and number in char) of a card.  Define in main() an array of structure card having size 48.  Take in a sequence of cards as input, and store the sequence in a string variable; for example, scanf("%[^\n]s", s) to store it in s. Each card should be a pair of characters (e.g., 4C stands for 4 of Clubs, AD stands of Ace of Diamonds, etc.). Thus, the first character in the pair is the number and the second is the suit. The sequence should be a space-separated sequence of such pairs. You may assume that the cards are all distinct.  Extract the card information from the string and populate the array of cards.  Card ordering: Principle is suits first, numbers next. Find the smallest card and exchange it with the 1st card. Now, from the last cards, find their smallest and exchange it with their 1st card. Next, from the last cards, find their smallest and exchange it with their 1st card. And so on.  Print the ordered cards. While printing, you should print the actual symbols of the suits. That is done as follows. Declare globally the following strings:

Back to Lab Problems
Functions and Recursions/Strings/Problem #2

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #2

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.