From af5a7dd2e47c3597e2ed1215c8d08c3ef574c698 Mon Sep 17 00:00:00 2001 From: alexmichel1084 <39660411+alexmichel1084@users.noreply.github.com> Date: Fri, 26 Oct 2018 11:42:38 +0300 Subject: [PATCH 1/5] task2 mihailov alex --- gradle/wrapper/gradle-wrapper.jar | Bin 54413 -> 54413 bytes .../cet/javabasics/WarAndPeaceExercise.java | 66 ++++++++++++++---- 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 0d4a9516871afd710a9d84d89e31ba77745607bd..1948b9074f1016d15d505d185bc3f73deb82d8c8 100644 GIT binary patch delta 64 zcmeBO$=th=d4f5M=jU(k6RjgzKNNi|Vw`+1ReIx=phH{?3<2Kk9Pfm6L?#Oy_6IB4 PoP7A601H^i^@;}oU3MB9 delta 64 zcmeBO$=th=d4f61&s)=~CR#_bek%G{#5nn2s`SP!L5H|l7y`W6IVzO3lP3!t_6IB4 PoP7A601H^i^@;}ochnli diff --git a/src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java b/src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java index 1ff35c2..d62186a 100644 --- a/src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java +++ b/src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java @@ -1,21 +1,63 @@ package ru.ifmo.cet.javabasics; -import java.nio.file.Path; -import java.nio.file.Paths; +import java.io.IOException; +import java.util.*; +import java.io.File; -public class WarAndPeaceExercise { - public static String warAndPeace() { - final Path tome12Path = Paths.get("src", "main", "resources", "WAP12.txt"); - final Path tome34Path = Paths.get("src", "main", "resources", "WAP34.txt"); +public class WarAndPeaceExercise { - // TODO map lowercased words to its amount in text and concatenate its entries. - // TODO If word "котик" occurred in text 23 times then its entry would be "котик - 23\n". - // TODO Entries in final String should be also sorted by amount and then in alphabetical order if needed. - // TODO Also omit any word with lengths less than 4 and frequency less than 10 + public static String warAndPeace() throws IOException { +//считывание в мапу + Scanner in = new Scanner(new File("src/main/resources/WAP12.txt")); + HashMap vocabulary= new HashMap<>(); + readWords(in, vocabulary); + in = new Scanner(new File("src/main/resources/WAP34.txt")); + readWords(in, vocabulary); +//удаление слов<10 + for(Iterator> it=vocabulary.entrySet().iterator();it.hasNext();) { + HashMap.Entry entry = it.next(); + if (entry.getValue() < 10) { + it.remove(); + } + } + ArrayList res_array= new ArrayList<>(); + while (!vocabulary.isEmpty()){ + HashMap.Entry max=vocabulary.entrySet().iterator().next(); + for (Map.Entry pair : vocabulary.entrySet()) { + if (max.getValue() < pair.getValue()) { + max = pair; + } else if (max.getValue().equals(pair.getValue())) { + if (max.getKey().compareTo(pair.getKey()) > 0) { + max = pair; + } + } + } + String string=max.getKey()+ " - "+max.getValue(); + res_array.add(string); + vocabulary.remove(max.getKey()); + } - throw new UnsupportedOperationException(); + String res_string=""; + for(String s:res_array) { + res_string+=s+"\n"; + } + res_string = res_string.substring(0, res_string.length() - 1); + return res_string; + } + public static void readWords(Scanner in, HashMap vocabulary) { + while(in.hasNext()){ + String[] words= (in.nextLine().toLowerCase().replaceAll("[^a-z\u0430-\u044f]", " ")).split(" "); + for (String word:words) { + if(word.length()<4) continue; + Integer value=vocabulary.get(word); + if (vocabulary.get(word) == null) { + vocabulary.put(word,1); + }else{ + vocabulary.put(word,++value); + } + } + } } - } \ No newline at end of file From fa5f1f2988f2b3de16436f1651a63d979ebe875e Mon Sep 17 00:00:00 2001 From: alexmichel1084 <39660411+alexmichel1084@users.noreply.github.com> Date: Fri, 26 Oct 2018 15:52:55 +0300 Subject: [PATCH 2/5] task 2 mihailov alex --- .idea/gradle.xml | 18 +++++++++++ ..._com_google_code_findbugs_jsr305_1_3_9.xml | 9 ++++++ ...orprone_error_prone_annotations_2_0_18.xml | 11 +++++++ .../Gradle__com_google_guava_guava_22_0.xml | 11 +++++++ ...m_google_j2objc_j2objc_annotations_1_1.xml | 11 +++++++ ...__org_apache_commons_commons_lang3_3_4.xml | 11 +++++++ ..._org_apiguardian_apiguardian_api_1_0_0.xml | 11 +++++++ ...s_mojo_animal_sniffer_annotations_1_14.xml | 11 +++++++ ..._junit_jupiter_junit_jupiter_api_5_2_0.xml | 11 +++++++ ...nit_jupiter_junit_jupiter_engine_5_2_0.xml | 11 +++++++ ..._platform_junit_platform_commons_1_2_0.xml | 11 +++++++ ...t_platform_junit_platform_engine_1_2_0.xml | 11 +++++++ ...radle__org_opentest4j_opentest4j_1_1_0.xml | 11 +++++++ .idea/misc.xml | 6 ++++ .idea/modules.xml | 8 +++++ .idea/vcs.xml | 6 ++++ IFMO_JAVA_Basics_20182009.iml | 31 +++++++++++++++++++ 17 files changed, 199 insertions(+) create mode 100644 .idea/gradle.xml create mode 100644 .idea/libraries/Gradle__com_google_code_findbugs_jsr305_1_3_9.xml create mode 100644 .idea/libraries/Gradle__com_google_errorprone_error_prone_annotations_2_0_18.xml create mode 100644 .idea/libraries/Gradle__com_google_guava_guava_22_0.xml create mode 100644 .idea/libraries/Gradle__com_google_j2objc_j2objc_annotations_1_1.xml create mode 100644 .idea/libraries/Gradle__org_apache_commons_commons_lang3_3_4.xml create mode 100644 .idea/libraries/Gradle__org_apiguardian_apiguardian_api_1_0_0.xml create mode 100644 .idea/libraries/Gradle__org_codehaus_mojo_animal_sniffer_annotations_1_14.xml create mode 100644 .idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_api_5_2_0.xml create mode 100644 .idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_engine_5_2_0.xml create mode 100644 .idea/libraries/Gradle__org_junit_platform_junit_platform_commons_1_2_0.xml create mode 100644 .idea/libraries/Gradle__org_junit_platform_junit_platform_engine_1_2_0.xml create mode 100644 .idea/libraries/Gradle__org_opentest4j_opentest4j_1_1_0.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 IFMO_JAVA_Basics_20182009.iml diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..d83d030 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_google_code_findbugs_jsr305_1_3_9.xml b/.idea/libraries/Gradle__com_google_code_findbugs_jsr305_1_3_9.xml new file mode 100644 index 0000000..63b7b35 --- /dev/null +++ b/.idea/libraries/Gradle__com_google_code_findbugs_jsr305_1_3_9.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_google_errorprone_error_prone_annotations_2_0_18.xml b/.idea/libraries/Gradle__com_google_errorprone_error_prone_annotations_2_0_18.xml new file mode 100644 index 0000000..eb64dcb --- /dev/null +++ b/.idea/libraries/Gradle__com_google_errorprone_error_prone_annotations_2_0_18.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_google_guava_guava_22_0.xml b/.idea/libraries/Gradle__com_google_guava_guava_22_0.xml new file mode 100644 index 0000000..4c947ec --- /dev/null +++ b/.idea/libraries/Gradle__com_google_guava_guava_22_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__com_google_j2objc_j2objc_annotations_1_1.xml b/.idea/libraries/Gradle__com_google_j2objc_j2objc_annotations_1_1.xml new file mode 100644 index 0000000..ab45264 --- /dev/null +++ b/.idea/libraries/Gradle__com_google_j2objc_j2objc_annotations_1_1.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_apache_commons_commons_lang3_3_4.xml b/.idea/libraries/Gradle__org_apache_commons_commons_lang3_3_4.xml new file mode 100644 index 0000000..f99c825 --- /dev/null +++ b/.idea/libraries/Gradle__org_apache_commons_commons_lang3_3_4.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_apiguardian_apiguardian_api_1_0_0.xml b/.idea/libraries/Gradle__org_apiguardian_apiguardian_api_1_0_0.xml new file mode 100644 index 0000000..1a15019 --- /dev/null +++ b/.idea/libraries/Gradle__org_apiguardian_apiguardian_api_1_0_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_codehaus_mojo_animal_sniffer_annotations_1_14.xml b/.idea/libraries/Gradle__org_codehaus_mojo_animal_sniffer_annotations_1_14.xml new file mode 100644 index 0000000..72ee118 --- /dev/null +++ b/.idea/libraries/Gradle__org_codehaus_mojo_animal_sniffer_annotations_1_14.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_api_5_2_0.xml b/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_api_5_2_0.xml new file mode 100644 index 0000000..922f74f --- /dev/null +++ b/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_api_5_2_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_engine_5_2_0.xml b/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_engine_5_2_0.xml new file mode 100644 index 0000000..467a446 --- /dev/null +++ b/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_engine_5_2_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_junit_platform_junit_platform_commons_1_2_0.xml b/.idea/libraries/Gradle__org_junit_platform_junit_platform_commons_1_2_0.xml new file mode 100644 index 0000000..dc731cc --- /dev/null +++ b/.idea/libraries/Gradle__org_junit_platform_junit_platform_commons_1_2_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_junit_platform_junit_platform_engine_1_2_0.xml b/.idea/libraries/Gradle__org_junit_platform_junit_platform_engine_1_2_0.xml new file mode 100644 index 0000000..22ae452 --- /dev/null +++ b/.idea/libraries/Gradle__org_junit_platform_junit_platform_engine_1_2_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Gradle__org_opentest4j_opentest4j_1_1_0.xml b/.idea/libraries/Gradle__org_opentest4j_opentest4j_1_1_0.xml new file mode 100644 index 0000000..f54f419 --- /dev/null +++ b/.idea/libraries/Gradle__org_opentest4j_opentest4j_1_1_0.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..9594111 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..069c6ce --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/IFMO_JAVA_Basics_20182009.iml b/IFMO_JAVA_Basics_20182009.iml new file mode 100644 index 0000000..f33c11a --- /dev/null +++ b/IFMO_JAVA_Basics_20182009.iml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 106f104aaf768b2483b20b5cdfcb114bf7ec0ce1 Mon Sep 17 00:00:00 2001 From: alexmichel1084 <39660411+alexmichel1084@users.noreply.github.com> Date: Mon, 3 Dec 2018 19:27:46 +0300 Subject: [PATCH 3/5] new task 2 recreate --- src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java b/src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java index d62186a..f058199 100644 --- a/src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java +++ b/src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java @@ -38,7 +38,7 @@ public static String warAndPeace() throws IOException { res_array.add(string); vocabulary.remove(max.getKey()); } - +//a String res_string=""; for(String s:res_array) { res_string+=s+"\n"; From ddeeaf960fb8f2b399df31fc452688a1650babd0 Mon Sep 17 00:00:00 2001 From: alexmichel1084 <39660411+alexmichel1084@users.noreply.github.com> Date: Mon, 3 Dec 2018 19:34:07 +0300 Subject: [PATCH 4/5] lala --- src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java b/src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java index f058199..26a7c7e 100644 --- a/src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java +++ b/src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java @@ -41,7 +41,7 @@ public static String warAndPeace() throws IOException { //a String res_string=""; for(String s:res_array) { - res_string+=s+"\n"; + res_string=s.concat("\n"); } res_string = res_string.substring(0, res_string.length() - 1); return res_string; From 530d10245cf3643f26b4ec33da95520572a94ccb Mon Sep 17 00:00:00 2001 From: alexmichel1084 <39660411+alexmichel1084@users.noreply.github.com> Date: Mon, 3 Dec 2018 19:49:20 +0300 Subject: [PATCH 5/5] lala2 --- src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java b/src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java index 26a7c7e..980c805 100644 --- a/src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java +++ b/src/main/java/ru/ifmo/cet/javabasics/WarAndPeaceExercise.java @@ -38,7 +38,6 @@ public static String warAndPeace() throws IOException { res_array.add(string); vocabulary.remove(max.getKey()); } -//a String res_string=""; for(String s:res_array) { res_string=s.concat("\n");