set equality problem
Time Limit: 1000 ms
Memory Limit: 65536 KiB
Problem Description
Given two sets S and T, try to design a Monte Carlo algorithm to determine whether S and T are equal.
Design a Las Vegas algorithm to determine whether given sets S and T are equal.
Design a Las Vegas algorithm to determine whether given sets S and T are equal.
Input
The first line of the input data has a positive integer n (n≤10000), which represents the size of the set. The next 2 lines, each with n positive integers, represent the elements in the sets S and T, respectively.
Output
will calculate the conclusion output. If the sets S and T are equal, output YES, otherwise output NO.
Sample Input
3 2 3 7 7 2 3
Sample Output
YES
Hint
Source
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n; int i; String str; List<String>list1 = new ArrayList<String>(); List<String>list2 = new ArrayList<String>(); n = input.nextInt(); for(i = 0; i < n; i++) { str = input.next(); list1.add(str); } for(i = 0; i < n; i++) { str = input.next(); list2.add(str); } if(list1.containsAll(list2)) { System.out.println("YES"); } else { System.out.println("NO"); } } }Str1.containsAll (Str2): Determine whether the set Str1 contains all the elements in Str2, and the order of the elements of the two sets can be different.