24h購物| | PChome| 登入
2012-05-16 07:33:39| 人氣2,972| 回應0 | 上一篇 | 下一篇

[UVA] 496 - Simply Subsets

推薦 0 收藏 0 轉貼0 訂閱站台


 Simply Subsets 

After graduating from the University of Notre Dame, you obtained a job at Top Shelf Software, Inc., as an entry-level computer engineer. On the first day, your manager sits down with you and tasks you with the following job: ``We want to see how well you understand computer programming and the abstract science behind it. As an evaluation for all of our new hires, we require them to write a program to determine the relationship between pairs of sets. I'm quite sure that you'll do well; my confidence is high. Here's a list of requirements for what the program should do. Good luck.''

Input

Your program should accept an even number of lines of text. Each pair of lines will represent two sets; the first line represents set A, the second line represents set B. Each line of text (set) will be a list of distinct integers.

Output

After each pair of lines has been read in, the sets should be compared and one of the following responses should be output:

  • A is a proper subset of B
  • B is a proper subset of A
  • A equals B
  • A and B are disjoint
  • I'm confused!

Sample Input

55 27
55 27
9 24 1995
9 24
1 2 3
1 2 3 4
1 2 3
4 5 6
1 2
2 3

Sample Output

A equals B
B is a proper subset of A
A is a proper subset of B
A and B are disjoint
I'm confused!



#include <iostream>
#include <sstream>
#include <cstdio>
using namespace std;

int main() {
    stringstream sin;
    string line;
    while(getline(cin, line)) {
        int A[100], B[100];
        int At = 0, Bt = 0, num, i, j;
        sin.clear();
        sin << line;
        while(sin >> num)
            A[At++] = num;
        getline(cin, line);
        sin.clear();
        sin << line;
        while(sin >> num)
            B[Bt++] = num;
        int Act = 0, Bct = 0;
        for(i = 0; i < At; i++) {
            for(j = 0; j < Bt; j++) {
                if(A[i] == B[j]) {
                    Act++;
                    break;
                }
            }
        }
        for(i = 0; i < Bt; i++) {
            for(j = 0; j < At; j++) {
                if(B[i] == A[j]) {
                    Bct++;
                    break;
                }
            }
        }
        if(At == Act && At < Bt)
            puts("A is a proper subset of B");
        else if(Bt == Bct && Bt < At)
            puts("B is a proper subset of A");
        else if(At == Bt && Act == At && Bct == Bt)
            puts("A equals B");
        else if(Act == 0 && Bct == 0)
            puts("A and B are disjoint");
        else
            puts("I'm confused!");
    }
    return 0;
}

台長: Morris
人氣(2,972) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][DP最大矩形] 10667 - Largest Block
此分類上一篇:[UVA] 725 - Division

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文