andy6804tw
3/29/2017 - 4:18 AM

## https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=437 這題只是數值比對有四種情況 1.A equals B (兩串列相等) 2.

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=437

``````import java.util.*;

public class Main {

public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
while (scn.hasNext()) {
String str1[] = scn.nextLine().split(" "), str2[] = scn.nextLine().split(" ");
int arr1[] = new int[str1.length], arr2[] = new int[str2.length];
for (int i = 0; i < arr1.length; i++)
arr1[i] = Integer.parseInt(str1[i]);
for (int i = 0; i < arr2.length; i++)
arr2[i] = Integer.parseInt(str2[i]);
Arrays.sort(arr1);
Arrays.sort(arr2);
if (arr1.length == arr2.length) { // 先判斷兩串列依樣長時
int i = 0;
int count = 0;
for (i = 0; i < arr1.length; i++) {
for (int j = 0; j < arr2.length; j++) {
if (arr1[i] == arr2[j]) {
count++;
}
}
}
if (count == arr1.length)
System.out.println("A equals B");
else if (count == 0)
System.out.println("A and B are disjoint");
else
System.out.println("I'm confused!");

} else if (arr1.length > arr2.length) {// 當arr1(A)長度比arr2(B)長時
int count = 0;
for (int i = 0; i < arr1.length; i++) {
for (int j = 0; j < arr2.length; j++) {
if (arr1[i] == arr2[j]) {
count++;
break;
}
}
}
if (count == arr2.length)
System.out.println("B is a proper subset of A");
else if (count > 0)
System.out.println("I'm confused!");
else
System.out.println("A and B are disjoint");

} else if (arr1.length < arr2.length) {// 當arr1(A)長度比arr2(B)短時
int count = 0;
for (int i = 0; i < arr2.length; i++) {
for (int j = 0; j < arr1.length; j++) {
if (arr2[i] == arr1[j]) {
count++;
break;
}
}
}
if (count == arr1.length)
System.out.println("A is a proper subset of B");
else if (count > 0)
System.out.println("I'm confused!");
else
System.out.println("A and B are disjoint");

}
}
}
/*
題目：Q496 : Simply Subsets
作者：1010
時間：西元 2017 年 3 月 28 日*/
}``````