-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommon Elements.java
More file actions
46 lines (39 loc) · 1.12 KB
/
Common Elements.java
File metadata and controls
46 lines (39 loc) · 1.12 KB
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
import java.util.Scanner;
import java.util.TreeMap;
import java.util.ArrayList;
class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
TreeMap<Integer,Integer> map=new TreeMap<>();
ArrayList<Integer> ans=new ArrayList<>();
while(sc.hasNext())
{
if(sc.hasNextInt()){
int x=sc.nextInt();
if(map.containsKey(x))
{
map.put(x,map.get(x)+1);
}
else
{
map.put(x,1);
}
if(map.get(x)==3)
ans.add(x);
}
else
{
sc.next();
}
}
if(ans.size()==0)
{
System.out.println("No Elements");
return;
}
for(int i=0;i<ans.size();i++)
{
System.out.print(ans.get(i)+" ");
}
}
}