Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
package com.pr3.bsbo_08_19.TimofeyKondakov.task13; import java.util.ArrayList; import java.util.HashMap; import java.util.Scanner; public class Task13 { public static final int LINES_COUNT = 3; public void Ex13(){ // 1. Ввести с клавиатуры в список строк 20 слов. // 2. Подсчитать, сколько одинаковых слов в этом списке. Результат // представить в виде словаря Map
, где // первый параметр – уникальная строка, // второй – число (сколько раз данная строка встречалась в списке). var in = new Scanner(System.in); var wordToCountMap = new HashMap
(); int readedLinesCount = 0; while (readedLinesCount < LINES_COUNT && in.hasNextLine()) { var ln = in.nextLine(); if (ln.isBlank()) { System.out.println("Skiped empty line!"); } else { var words = ln.split(" "); for (var word : words) { var count = wordToCountMap.get(word); if (count == null) { count = 0; } wordToCountMap.put(word, count + 1); } readedLinesCount++; } } if (readedLinesCount < LINES_COUNT) { System.err.println("Not all lines was readed! Excepted " + LINES_COUNT + ", but was " + readedLinesCount); System.exit(1); } System.out.println("Result: " + wordToCountMap); in.close(); // Scanner in = new Scanner(System.in); // // System.out.println("Enter text: "); // // var str = new ArrayList
(); // int[] array_count = new int[20]; // String str1; // // for(int i = 0; i < 20; i++){ // System.out.println("Enter str number " + i); // str1 = in.nextLine(); // str.add(i,str1); // array_count[i] = 0; // } // int check = 0; // boolean check_count = false; // for(int i = 0; i < str.size(); i++) { // for(int j = 0; j < str.size(); j++) { // for(int k = 0; k < str.get(i).length(); k++){ // if(str.get(i).length() == str.get(j).length()){ // if(str.get(i).charAt(k) == str.get(j).charAt(k)){ // check++; // } // } // if(check == str.get(i).length()){ // check_count = true; // } // } // check = 0; // if(check_count){ // check_count = false; // array_count[i]++; // } // } // } // for(int i = 0; i < str.size(); i++) { // System.out.println("Str: " + str.get(i) + " repeat is " + array_count[i]); // } } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)