-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunctionalfun.java
82 lines (63 loc) · 1.7 KB
/
functionalfun.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import java.util.ArrayList;
import java.util.Scanner;
public class functionalfun {
public static void main( String[] args ) {
Scanner scan = new Scanner(System.in);
while( scan.hasNextLine() ){
boolean injective = true;
boolean surjective = true;
boolean notfunc = false;
scan.next();
/**String[] domain = **/scan.nextLine().trim().split( " " );
scan.next();
String[] codomain = scan.nextLine().trim().split( " " );
int p = scan.nextInt();
point[] points = new point[p];
int counter = 0;
while( p --> 0 ) {
String x = scan.next();
scan.next();
String y = scan.nextLine().trim();
points[ counter ] = new point( x, y );
counter++;
}
ArrayList< String > visited = new ArrayList< String >();
for( point j : points ){
if( visited.contains( j.y ) )
injective = false;
else
visited.add( j.y );
}
if( codomain.length != visited.size() )
surjective = false;
ArrayList< String > xs = new ArrayList< String >();
for( point j : points ){
if( xs.contains( j.x ) ) {
notfunc = true;
break;
}
else
xs.add( j.x );
}
if( notfunc )
System.out.println( "not a function" );
else if(injective && surjective)
System.out.println( "bijective" );
else if( injective )
System.out.println( "injective" );
else if(surjective)
System.out.println( "surjective" );
else
System.out.println( "neither injective nor surjective" );
}
scan.close();
}
}
class point {
String x;
String y;
public point( String x, String y ) {
this.x = x;
this.y = y;
}
}