online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { /** * ΠœΠ΅Ρ‚ΠΎΠ΄ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π²Π΅Ρ€Π½ΡƒΡ‚ΡŒ список людСй с Ρ„Π°ΠΌΠΈΠ»ΠΈΠ΅ΠΉ ΠΈΠ»ΠΈ ΠΈΠΌΠ΅Π½Π΅ΠΌ King */ public static List<String> methodOne(List<String> names) { return names.stream() .filter(s -> s.contains("King")) .collect(Collectors.toList()); } /** * ΠœΠ΅Ρ‚ΠΎΠ΄ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π²Π΅Ρ€Π½ΡƒΡ‚ΡŒ список ΡƒΠ½ΠΈΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… Ρ„Π°ΠΌΠΈΠ»ΠΈΠΉ (2 позиция Π² строкС) */ public static List<String> methodTwo(List<String> names) { return names.stream() .map(s -> s.substring(s.indexOf(" ") + 1)) .distinct() .collect(Collectors.toList()); } /** * ΠœΠ΅Ρ‚ΠΎΠ΄ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π²Π΅Ρ€Π½ΡƒΡ‚ΡŒ список ΡƒΠ½ΠΈΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… ΠΈΠΌΠ΅Π½, Π½Π°Ρ‡ΠΈΠ½Π°ΡŽΡ‰ΠΈΡ…ΡΡ с L */ public static List<String> methodThree(List<String> names) { return names.stream() .filter(s -> s.startsWith("L")) .map(s -> s.substring(0, s.indexOf(" "))) .distinct() .collect(Collectors.toList()); } /** * ΠœΠ΅Ρ‚ΠΎΠ΄ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π²Π΅Ρ€Π½ΡƒΡ‚ΡŒ список ΡƒΠ½ΠΈΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… Ρ„Π°ΠΌΠΈΠ»ΠΈΠΉ, Π½Π°Ρ‡ΠΈΠ½Π°ΡŽΡ‰ΠΈΡ…ΡΡ с W, отсортированный ΠΏΠΎ Π°Π»Ρ„Π°Π²ΠΈΡ‚Ρƒ */ public static List<String> methodFour(List<String> names) { return names.stream() .map(s -> s.substring(s.indexOf(" ") + 1)) .filter(s ->s.startsWith("W")) .distinct() .sorted() .collect(Collectors.toList()); } /** * ΠœΠ΅Ρ‚ΠΎΠ΄ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π²Π΅Ρ€Π½ΡƒΡ‚ΡŒ количСство ΠΈΠΌΠ΅Π½ Π΄Π»ΠΈΠ½Π΅Π΅ Ρ‡Π΅ΠΌ 6 символов */ public static Integer methodFive(List<String> names) { return (int) names.stream() .map(s -> s.substring(0, s.indexOf(" "))) .filter(s -> s.length() > 6) .distinct() .count(); } /** * ΠœΠ΅Ρ‚ΠΎΠ΄ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π²Π΅Ρ€Π½ΡƒΡ‚ΡŒ суммарноС количСство ΡƒΠ½ΠΈΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… ΠΈΠΌΡ‘Π½ ΠΈ Ρ„Π°ΠΌΠΈΠ»ΠΈΠΉ, Π΄Π»ΠΈΠ½Π½Π΅Π΅ 5 символов */ public static Integer methodSix(List<String> names) { return (int) names.stream() .flatMap(s -> Arrays.stream(s.split("\\s+"))) .filter(s -> s.length() > 5) .distinct() .count(); } /** * ΠœΠ΅Ρ‚ΠΎΠ΄ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π²Π΅Ρ€Π½ΡƒΡ‚ΡŒ ΠΈΠΌΠ΅Π½Π° людСй, Ρ‡ΡŒΡ фамилия начинаСтся с K ΠΈΠ»ΠΈ S, Π² Ρ„ΠΎΡ€ΠΌΠ°Ρ‚Π΅ имя + пСрвая Π±ΡƒΠΊΠ²Π° Ρ„Π°ΠΌΠΈΠ»ΠΈΠΈ, * Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ "David Z.". Бписок Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±Ρ‹Ρ‚ΡŒ отсортирован ΠΏΠΎ Π°Π»Ρ„Π°Π²ΠΈΡ‚Ρƒ ΠΈ ΡΠΎΡΡ‚ΠΎΡΡ‚ΡŒ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ ΠΈΠ· ΡƒΠ½ΠΈΠΊΠ°Π»ΡŒΠ½Ρ‹Ρ… Π·Π½Π°Ρ‡Π΅Π½ΠΈΠΉ */ public static List<String> methodSeven(List<String> names) { return names.stream() .filter(s -> s.matches("\\w+ [KS]\\w+")) .map(s -> s.substring(0, s.indexOf(" ") + 2) + ".") .sorted() .distinct() .collect(Collectors.toList()); } public static void main(String[] args) { printTestCase(KINGS, methodOne(FULL_NAMES)); printTestCase(UNIQ_SURNAMES, methodTwo(FULL_NAMES)); printTestCase(NAMES_STARTS_WITH_L, methodThree(FULL_NAMES)); printTestCase(SURNAMES_STARTS_WITH_W_SORTED, methodFour(FULL_NAMES)); printTestCase(NAMES_LONGER_THAN_SIX, methodFive(FULL_NAMES)); printTestCase(NAMES_AND_SURNAMES_LONGER_THAN_FIVE, methodSix(FULL_NAMES)); printTestCase(NAMES_WITH_LETTER_SORTED, methodSeven(FULL_NAMES)); } private static final List<String> FULL_NAMES = List.of( "Joseph Smith", "Thomas Doyle", "Ronald Pratt", "Thomas Spencer", "King Lee", "Gregory Smith", "Leroy Zimmerman", "Lee Smith", "Michael Harrington", "Lee Daniels", "Eugene Williams", "Lee Terry", "Arnold Fowler", "Billy Harrison", "Lee Bennett", "Lee Evans", "Ronald Diaz", "Leonard King", "Timothy Smith", "George Lee", "King Mann", "Dean Wright", "Lee Richards", "Arthur Smith", "Gregory Moore", "Larry Hall", "Patrick Moore", "Ben Smith", "Jose Smith", "Michael Parker", "Jeff Smith", "Larry Thompson", "Joel Smith", "Ivan Spencer", "Robert Anderson", "Lee Phillips", "Stanley Warren", "William Sanchez", "Jamie McDonald", "David Griffith", "Terry Hicks", "Larry Johnson", "Mike Fowler", "Ivan Shaw", "Lee Stevenson", "Lee Powell", "Larry King", "Lee Mitchell", "Robert Diaz", "John Fowler", "Todd Cox", "David James", "Willie Bryan", "Thomas Howard", "Ivan Stanley", "Paul Harper", "Robert King", "David Stanley", "Dale Fletcher", "Larry Mullins", "Arthur King", "Robert King", "John King", "Larry Coleman", "Anthony King", "Ivan Johnson", "Ivan Mann", "Michael Diaz", "Leroy Smith", "King Wagner", "David Stanley", "Ivan Willis", "Ivan Stewart", "Frank King", "Roland Jones", "Leroy Warren", "Rodney Bailey", "David King", "Randy King", "James Soto", "James Parker", "Bobby Stanley", "Leroy Cooper", "Michael Woods", "David Mann", "Lee Padilla", "Samuel Shelton", "Jesse Simmons", "Ivan Stanley", "Lee Gibson", "Bryan King", "David Brooks", "David Fowler", "Robert Fowler", "Ivan King", "Donald Thomas", "Leroy Ramsey", "Russell Diaz", "David Torres" ); private static final List<String> KINGS = List.of( "King Lee", "Leonard King", "King Mann", "Larry King", "Robert King", "Arthur King", "Robert King", "John King", "Anthony King", "King Wagner", "Frank King", "David King", "Randy King", "Bryan King", "Ivan King" ); private static final List<String> UNIQ_SURNAMES = List.of( "Smith", "Doyle", "Pratt", "Spencer", "Lee", "Zimmerman", "Harrington", "Daniels", "Williams", "Terry", "Fowler", "Harrison", "Bennett", "Evans", "Diaz", "King", "Mann", "Wright", "Richards", "Moore", "Hall", "Parker", "Thompson", "Anderson", "Phillips", "Warren", "Sanchez", "McDonald", "Griffith", "Hicks", "Johnson", "Shaw", "Stevenson", "Powell", "Mitchell", "Cox", "James", "Bryan", "Howard", "Stanley", "Harper", "Fletcher", "Mullins", "Coleman", "Wagner", "Willis", "Stewart", "Jones", "Bailey", "Soto", "Cooper", "Woods", "Padilla", "Shelton", "Simmons", "Gibson", "Brooks", "Thomas", "Ramsey", "Torres" ); private static final List<String> NAMES_STARTS_WITH_L = List.of( "Leroy", "Lee", "Leonard", "Larry" ); private static final List<String> SURNAMES_STARTS_WITH_W_SORTED = List.of( "Wagner", "Warren", "Williams", "Willis", "Woods", "Wright" ); private static final List<String> NAMES_WITH_LETTER_SORTED = List.of( "Anthony K.", "Arthur K.", "Arthur S.", "Ben S.", "Bobby S.", "Bryan K.", "David K.", "David S.", "Frank K.", "Gregory S.", "Ivan K.", "Ivan S.", "James S.", "Jeff S.", "Jesse S.", "Joel S.", "John K.", "Jose S.", "Joseph S.", "Larry K.", "Lee S.", "Leonard K.", "Leroy S.", "Randy K.", "Robert K.", "Samuel S.", "Thomas S.", "Timothy S.", "William S." ); private static final Integer NAMES_LONGER_THAN_SIX = 9; private static final Integer NAMES_AND_SURNAMES_LONGER_THAN_FIVE = 61; public static String constLen(String str, int len) { StringBuilder sb = new StringBuilder(str); while (len-- - str.length() > 0) sb.append(" "); return sb.toString(); } public static void printTestCase(List<String> exp, List<String> act) { System.out.println(); Function<String, String> green = str -> "\u001B[32m" + str + "\u001B[0m"; Function<String, String> yellow = str -> "\u001B[33m" + str + "\u001B[0m"; System.out.println("ОТиданиС: " + yellow.apply(constLen(exp.toString(), 15))); System.out.println("Π Π΅Π°Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ: " + green.apply(constLen(act.toString(), 15))); System.out.print("RESULT "); if (Objects.equals(exp, act)) System.out.print("βœ…"); else System.out.print("❌"); System.out.println(); } public static void printTestCase(Integer exp, Integer act) { System.out.println(); Function<String, String> green = str -> "\u001B[32m" + str + "\u001B[0m"; Function<String, String> yellow = str -> "\u001B[33m" + str + "\u001B[0m"; System.out.println("ОТиданиС: " + yellow.apply(constLen(exp.toString(), 15))); System.out.println("Π Π΅Π°Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ: " + green.apply(constLen(act.toString(), 15))); System.out.print("RESULT "); if (Objects.equals(exp, act)) System.out.print("βœ…"); else System.out.print("❌"); System.out.println(); } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue