In computer science, a set is an abstract data type that can store certain values, without any particular order, and no repeated values(Wikipedia). {1, 2, 3) is an example of a set, but {1, 2, 2} is not a set. Today you will learn how to use sets in java by solving this problem. You are given n pairs of strings. Two pairs (a, b) and (e, d) are identical if a cand b=d. That also implies (a, b) is not same as (b, a). After taking each pair as input, you need to print number of unique pairs you currently have. Complete the code in the editor to solve this problem. Input Format In the first line, there will be an integer T denoting number of pairs. Each of the next T lines will contain two strings seperated by a single space. Constraints: • 1≤T≤ 100000 Length of each string is atmost 5 and will consist lower case letters only. Output Format Print T lines. In the line, print number of unique pairs you have after taking pair as input. Sample Input John tom John mary John ton mary anna mary anna

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 16PE: The implementation of a queue in an array, as given in this chapter, uses the variable count to...
icon
Related questions
Question
In computer science, a set is an abstract data type that can store certain values, without any particular order, and no repeated
values(Wikipedia). {1, 2, 3} is an example of a set, but {1, 2, 2) is not a set. Today you will learn how to use sets in java by
solving this problem.
You are given n pairs of strings. Two pairs (a, b) and (c,d) are identical if a cand b=d. That also implies (a, b) is not
same as (b, a). After taking each pair as input, you need to print number of unique pairs you currently have.
Complete the code in the editor to solve this problem.
Input Format
In the first line, there will be an integer T denoting number of pairs. Each of the next T lines will contain two strings seperated
by a single space.
Constraints:
• 1≤T≤ 100000
• Length of each string is atmost 5 and will consist lower case letters only.
Output Format
Print T lines. In the line, print number of unique pairs you have after taking it pair as input.
Sample Input
John tom
John mary
John tom
mary anna
mary anna
Transcribed Image Text:In computer science, a set is an abstract data type that can store certain values, without any particular order, and no repeated values(Wikipedia). {1, 2, 3} is an example of a set, but {1, 2, 2) is not a set. Today you will learn how to use sets in java by solving this problem. You are given n pairs of strings. Two pairs (a, b) and (c,d) are identical if a cand b=d. That also implies (a, b) is not same as (b, a). After taking each pair as input, you need to print number of unique pairs you currently have. Complete the code in the editor to solve this problem. Input Format In the first line, there will be an integer T denoting number of pairs. Each of the next T lines will contain two strings seperated by a single space. Constraints: • 1≤T≤ 100000 • Length of each string is atmost 5 and will consist lower case letters only. Output Format Print T lines. In the line, print number of unique pairs you have after taking it pair as input. Sample Input John tom John mary John tom mary anna mary anna
Sample Input
john tom
john mary
john tom
mary anna
mary anna
Sample Output
12233
imput
Explanation
• After taking the first input, you have only one pair: (ohn,tom)
. After taking the second input, you have two pairs: (john, tom) and (john, mary)
. After taking the third input, you still have two unique pairs.
. After taking the fourth input, you have three unique pairs: (ohn,tom) (john, mary) and (mary, anna)
. After taking the fifth input, you still have three unique pairs.
Transcribed Image Text:Sample Input john tom john mary john tom mary anna mary anna Sample Output 12233 imput Explanation • After taking the first input, you have only one pair: (ohn,tom) . After taking the second input, you have two pairs: (john, tom) and (john, mary) . After taking the third input, you still have two unique pairs. . After taking the fourth input, you have three unique pairs: (ohn,tom) (john, mary) and (mary, anna) . After taking the fifth input, you still have three unique pairs.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning