-
Notifications
You must be signed in to change notification settings - Fork 0
week 7 tasks added #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import java.util.*; | ||
|
|
||
| public class Linked_Hash_Set { | ||
|
||
| public static void main(String[] args) { | ||
| LinkedHashSet_operations operations = new LinkedHashSet_operations(); | ||
|
||
| Scanner scan = new Scanner(System.in); | ||
| int testNumber = scan.nextInt(); | ||
|
|
||
| for (int i = 0; i < testNumber; i++) { | ||
|
|
||
| int number_of_operations = scan.nextInt(); | ||
|
|
||
| for (int j = 0; j < number_of_operations; j++) { | ||
|
|
||
| String operation = scan.next(); | ||
| int number; | ||
|
|
||
| switch (operation) { | ||
| case "a": | ||
| number = scan.nextInt(); | ||
| operations.addValue(number); | ||
| break; | ||
|
|
||
| case "b": | ||
| operations.printSortedSet(); | ||
| break; | ||
|
|
||
| case "c": | ||
| number = scan.nextInt(); | ||
| operations.removeElement(number); | ||
| break; | ||
|
|
||
| case "d": | ||
| number = scan.nextInt(); | ||
| operations.findNumber(number); | ||
| break; | ||
|
|
||
| case "e": | ||
| operations.getSize(); | ||
| break; | ||
| } | ||
|
||
| } | ||
| } | ||
| } | ||
| static class LinkedHashSet_operations{ | ||
| LinkedHashSet<Integer> operations; | ||
| public LinkedHashSet_operations(){ | ||
| operations = new LinkedHashSet<>(); | ||
| } | ||
| private void addValue(int number){ | ||
| operations.add(number); | ||
| } | ||
| private void printSortedSet(){ | ||
| List<Integer> sortedNumbers = new ArrayList<>(operations); | ||
| Collections.sort(sortedNumbers); | ||
| for (Integer n : sortedNumbers) System.out.print(n + " "); | ||
| System.out.println(); | ||
| } | ||
| private void removeElement(int number){ | ||
| operations.remove(number); | ||
| } | ||
| private void findNumber(int number){ | ||
| System.out.println(operations.contains(number)); | ||
| } | ||
| private void getSize(){ | ||
| System.out.println(operations.size()); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import java.util.*; | ||
|
|
||
| public class Tree_Map { | ||
|
||
| public static void main(String[] args) { | ||
| Scanner scan = new Scanner(System.in); | ||
| TreeMap_operations map = new TreeMap_operations(); | ||
| int testNumber = scan.nextInt(); | ||
|
|
||
| for (int i = 0; i < testNumber; i++) { | ||
|
|
||
| int number_of_operations = scan.nextInt(); | ||
|
|
||
| for (int j = 0; j < number_of_operations; j++) { | ||
| String operation = scan.next(); | ||
| int value , key; | ||
|
|
||
| switch (operation) { | ||
| case "a": | ||
| key = scan.nextInt(); | ||
| value = scan.nextInt(); | ||
| map.addValue(key,value); | ||
| break; | ||
|
|
||
| case "b": | ||
| key = scan.nextInt(); | ||
| map.findKey(key); | ||
| break; | ||
|
||
|
|
||
| case "c": | ||
| map.getSize(); | ||
| break; | ||
|
|
||
| case "d": | ||
| key = scan.nextInt(); | ||
| map.removeElement(key); | ||
| break; | ||
|
|
||
| case "e": | ||
| map.printElements(); | ||
|
||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| static class TreeMap_operations{ | ||
| Map<Integer,Integer> operations = new TreeMap<>(); | ||
| public TreeMap_operations() { | ||
| operations= new TreeMap<>(); | ||
| } | ||
| private void addValue(int key,int value){ | ||
| operations.put(key,value); | ||
| } | ||
| private void findKey(int key){ | ||
| if(operations.containsKey(key)) System.out.println(operations.get(key)); else System.out.println(-1); | ||
| } | ||
| private void getSize(){ | ||
| System.out.println(operations.size()); | ||
| } | ||
| private void removeElement(int key){ | ||
| System.out.println(operations.remove(key)); | ||
| } | ||
| private void printElements(){ | ||
| for(Map.Entry m: operations.entrySet()) System.out.println(m.getKey() + ":" + m.getValue()); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import java.util.*; | ||
|
|
||
| public class Word_Dictionary { | ||
|
|
||
| public static void main(String[]args){ | ||
| WordDictionary dict = new WordDictionary(); | ||
| dict.addWord('a',"apple"); | ||
| dict.addWord('a',"astronaut"); | ||
| dict.addWord('b',"ball"); | ||
| dict.addWord('c',"camera"); | ||
| dict.addWord('d',"dress"); | ||
| dict.printValues('a'); | ||
| dict.printDictionay(); | ||
| } | ||
|
|
||
| static class WordDictionary { | ||
| Map<Character,ArrayList<String>> word_dectionary; | ||
| public WordDictionary(){ | ||
| word_dectionary = new HashMap<>(); | ||
| for(char c='a';c<'z';c++){ | ||
| word_dectionary.put(c,new ArrayList<>()); | ||
| } | ||
| } | ||
| public void addWord(char key,String word){ | ||
| word_dectionary.get(key).add(word); | ||
|
||
| } | ||
| public void printDictionay(){ | ||
| for(Map.Entry m : word_dectionary.entrySet()){ | ||
| System.out.println(m.getKey() + ": " + m.getValue()); | ||
| } | ||
| } | ||
| public void printValues(char key){ | ||
| System.out.println(word_dectionary.get(key)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same comments in other tasks |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import java.util.*; | ||
|
|
||
| public class set { | ||
| public static void main(String[] args) { | ||
| Set_operations operations = new Set_operations(); | ||
| Scanner scan = new Scanner(System.in); | ||
| int testNumber = scan.nextInt(); | ||
|
|
||
| for (int i = 0; i < testNumber; i++) { | ||
|
|
||
| int number_of_operations = scan.nextInt(); | ||
|
|
||
| for (int j = 0; j < number_of_operations; j++) { | ||
|
|
||
| String operation = scan.next(); | ||
| int number; | ||
|
|
||
| switch (operation) { | ||
| case "a": | ||
| number = scan.nextInt(); | ||
| operations.addValue(number); | ||
| break; | ||
|
|
||
| case "b": | ||
| operations.printSortedSet(); | ||
| break; | ||
|
|
||
| case "c": | ||
| number = scan.nextInt(); | ||
| operations.removeElement(number); | ||
| break; | ||
|
|
||
| case "d": | ||
| number = scan.nextInt(); | ||
| operations.findNumber(number); | ||
| break; | ||
|
|
||
| case "e": | ||
| operations.getSize(); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| static class Set_operations{ | ||
| Set<Integer> operations; | ||
| public Set_operations(){ | ||
| operations = new HashSet<>(); | ||
| } | ||
| private void addValue(int number){ | ||
| operations.add(number); | ||
| } | ||
| private void printSortedSet(){ | ||
| List<Integer> sortedNumbers = new ArrayList<>(operations); | ||
| Collections.sort(sortedNumbers); | ||
| for (Integer n : sortedNumbers) System.out.print(n + " "); | ||
| System.out.println(); | ||
| } | ||
| private void removeElement(int number){ | ||
| operations.remove(number); | ||
| } | ||
| private void findNumber(int number){ | ||
| System.out.println(operations.contains(number)); | ||
| } | ||
| private void getSize(){ | ||
| System.out.println(operations.size()); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print some text to make the user know how to use the application and what to do next
for example
Enter the number of test cases
Enter the number of queries
etc