FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaProgramming/HackerRank/Twenty.java at main · Varadraj75/JavaProgramming · GitHub
Varadraj75
/
JavaProgramming
Public
forked from
karterhhgg/JavaProgramming
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaProgramming
/
HackerRank
/
Twenty.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
60 lines (49 loc) · 1.52 KB
Breadcrumbs
JavaProgramming
/
HackerRank
/
Twenty.java
Copy path
File metadata and controls
60 lines (49 loc) · 1.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
After each operation, print the respective number of set bits in BitSet and BitSet as space-separated integers on a new line.
Sample Input
5 4
AND 1 2
SET 1 4
FLIP 2 2
OR 2 1
Sample Output
0 0
1 0
1 1
1 2
*/
package
HackerRank
;
import
java
.
io
.*;
import
java
.
util
.*;
import
java
.
text
.*;
import
java
.
math
.*;
import
java
.
util
.
regex
.*;
public
class
Twenty
{
public
static
void
main
(
String
[]
args
) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner
sc
=
new
Scanner
(
System
.
in
);
int
n
=
sc
.
nextInt
();
int
m
=
sc
.
nextInt
();
BitSet
[]
bitsets
=
new
BitSet
[
3
];
bitsets
[
1
] =
new
BitSet
(
n
);
bitsets
[
2
] =
new
BitSet
(
n
);
for
(
int
i
=
0
;
i
<
m
;
i
++) {
String
op
=
sc
.
next
();
int
set1
=
sc
.
nextInt
();
int
set2
=
sc
.
nextInt
();
if
(
op
.
equals
(
"AND"
)) {
bitsets
[
set1
].
and
(
bitsets
[
set2
]);
}
else
if
(
op
.
equals
(
"OR"
)) {
bitsets
[
set1
].
or
(
bitsets
[
set2
]);
}
else
if
(
op
.
equals
(
"XOR"
)) {
bitsets
[
set1
].
xor
(
bitsets
[
set2
]);
}
else
if
(
op
.
equals
(
"FLIP"
)) {
bitsets
[
set1
].
flip
(
set2
);
}
else
if
(
op
.
equals
(
"SET"
)) {
bitsets
[
set1
].
set
(
set2
);
}
System
.
out
.
println
(
bitsets
[
1
].
cardinality
() +
" "
+
bitsets
[
2
].
cardinality
());
}
sc
.
close
();
}
}
Back
|
FazBrowse Home
|
New Git URL