Created
September 22, 2015 13:45
-
-
Save komkanit/c007665e1d34e0064bbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// =========== Edit Student Detail Here ============ | |
// Program: set01.cs | |
// RankId: 09 | |
// Author: Komkanit Sujautra | |
// Id: 5810500412 | |
// Group: 1/11 | |
// Date: 17/9/2015 | |
//=================================================== | |
using System; | |
class set{ | |
public static void Main() | |
{ | |
char cut = ' '; | |
string a,b; | |
int [] sa = new int[100]; | |
int [] sb = new int[100]; | |
int [] uni = new int[100]; | |
int [] inter = new int[100]; | |
int [] minus = new int[100]; | |
int i,j,len,len2,lenu,leni = 0,lenm = 0,c = 0,d = 0; | |
Console.Write("Input set A: "); | |
a = Console.ReadLine(); | |
Console.Write("Input set B: "); | |
b = Console.ReadLine(); | |
string [] str = a.Split(cut); | |
len = str.Length; | |
for(i=0 ; i<len ; i++) | |
{ | |
sa[i] = int.Parse(str[i]); | |
if(sa[i] > 99 || sa[i] <0) | |
c = 1; | |
} | |
string [] str2 = b.Split(cut); | |
len2 = str2.Length; | |
for(i=0 ; i<len2 ; i++) | |
{ | |
sb[i] = int.Parse(str2[i]); | |
if(sb[i] > 99 || sb[i] <0) | |
d = 1; | |
} | |
if(c == 1) | |
{ | |
Console.Write("Input Error: "); | |
for(i=0 ; i<len ; i++) | |
{ | |
if(sa[i] > 99 || sa[i] <0) | |
Console.Write("<{0}> ",sa[i]); | |
else | |
Console.Write("{0} ",sa[i]); | |
} | |
Console.WriteLine(""); | |
} | |
if(d == 1) | |
{ | |
Console.Write("Input Error: "); | |
for(i=0 ; i<len2 ; i++) | |
{ | |
if(sb[i] > 99 || sb[i] <0) | |
Console.Write("<{0}> ",sb[i]); | |
else | |
Console.Write("{0} ",sb[i]); | |
} | |
Console.WriteLine(""); | |
} | |
if(c==0 && d==0) | |
{ | |
for(i = 0 ; i < len ; i++) | |
{ | |
uni[i] = sa[i]; | |
for(j = 0 ; j <len2 ; j++) | |
{ | |
if(sa[i] == sb[j]) | |
break; | |
} | |
if(j == len2) | |
{ | |
minus[lenm] = sa[i]; | |
lenm++; | |
} | |
} | |
lenu = len; | |
for(i = 0 ; i < len2 ; i++) | |
{ | |
for(j = 0 ; j < len ; j++) | |
{ | |
if(sb[i] == sa[j]) | |
{ | |
inter[leni] = sb[i]; | |
leni++; | |
break; | |
} | |
} | |
if(j == len) | |
{ | |
uni[lenu] = sb[i]; | |
lenu++; | |
} | |
} | |
Console.Write("A union B: "); | |
if(lenu != 0) | |
for(i=0 ; i<lenu ; i++) | |
Console.Write(uni[i]+ " "); | |
else | |
Console.Write("Empty Set"); | |
Console.WriteLine(""); | |
Console.Write("A intersect B: "); | |
if(leni !=0) | |
for(i=0 ; i<leni ; i++) | |
Console.Write(inter[i]+ " "); | |
else | |
Console.Write("Empty Set"); | |
Console.WriteLine(""); | |
Console.Write("A minus B: "); | |
if(lenm != 0) | |
for(i=0 ; i<lenm ; i++) | |
Console.Write(minus[i]+ " "); | |
else | |
Console.Write("Empty Set"); | |
Console.WriteLine(""); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment