-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathComputer_lessons(codefights).java
92 lines (68 loc) · 2 KB
/
Computer_lessons(codefights).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
83
84
85
86
87
88
89
90
91
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author shivam
*/
import java.util.*;
import java.util.List;
import java.util.ArrayList;
import java.util.TreeSet;
public class fffff {
public static void main(String[] args) {
String pros[] = {"Jack", "Leon", "Maria"};
String c[][] = {{"Computer repair", "Handyman", "House cleaning"},
{"Computer lessons", "Computer repair", "Data recovery service"},
{"Computer lessons", "House cleaning"}};
//String [][][] res= new String[5][1][1];
// System.out.println("shivam");
TreeSet<String> t = new TreeSet<String>();
int len=0;
for (int i=0;i<c.length;i++) {
for (int j=0;j<c[i].length;j++) {
if (t.add(c[i][j])) {
//System.out.print(c[i][j]+" ");
len++;
}
}
}
System.out.println(len);
//return res;
String res[][][]= new String[1][len][3];
int p=0;
Iterator itr;
itr = t.iterator();
TreeMap<String,List<String> > tmap;
tmap = new TreeMap<String,List<String>>();
while (itr.hasNext()) {
ArrayList<String> l = new ArrayList<String>();
String str=itr.next()+"";
// System.out.println(str);
for (int i=0;i<c.length;i++) {
for (int j=0;j<c[i].length;j++) {
if (c[i][j].equals(str)) {
l.add(pros[i]);
}
}
}
tmap.put(str,l);
// l.clear();
}
//printing TreeMap
for(Map.Entry m:tmap.entrySet()){
System.out.println(m.getKey()+" "+m.getValue());
}
}
}
/*OUTPUT
5
Computer lessons [Leon, Maria]
Computer repair [Jack, Leon]
Data recovery service [Leon]
Handyman [Jack]
House cleaning [Jack, Maria]
BUILD SUCCESSFUL (total time: 0 seconds)
*/