Java Program You will be given the source and destination of all the tickets in the form of a map, and you have to print
Posted: Fri May 20, 2022 10:07 am
Java Program
You will be given the source and destination of all the tickets
in the form of a map, and you have to print the itinerary from all
those tickets.
Note:
Input: The input will be in the following
format:
Output: The output should be in the following
format
Sample test case 1:
Input:
Output:
Sample test case 2:
Input:
Output:
Sample test case 3:
Input:
Output:
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Source {
public static void main(String[] args) {
Scanner in = new
Scanner(System.in);
// get the no of tickets from
input
int n = in.nextInt();
// map to store all the
tickets
Map<String, String> tickets = new
HashMap<String, String>();
// Store the source and destination
of the tickets to the map "tickets"
for (int i = 0; i < n; i++) {
tickets.put(in.next(),
in.next());
in.nextLine();
}
// write your code here
}
}
You will be given the source and destination of all the tickets
in the form of a map, and you have to print the itinerary from all
those tickets.
Note:
Input: The input will be in the following
format:
Output: The output should be in the following
format
Sample test case 1:
Input:
Output:
Sample test case 2:
Input:
Output:
Sample test case 3:
Input:
Output:
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Source {
public static void main(String[] args) {
Scanner in = new
Scanner(System.in);
// get the no of tickets from
input
int n = in.nextInt();
// map to store all the
tickets
Map<String, String> tickets = new
HashMap<String, String>();
// Store the source and destination
of the tickets to the map "tickets"
for (int i = 0; i < n; i++) {
tickets.put(in.next(),
in.next());
in.nextLine();
}
// write your code here
}
}