From fa5ac5e089ce263d6caa174fd5a2ca3050344928 Mon Sep 17 00:00:00 2001 From: dadgam3er Date: Tue, 8 Oct 2024 05:45:58 -0400 Subject: [PATCH] Tagless --- ExtratFour.java | 26 +++++++++++++ LinkedListed.java | 24 ++++++++++++ MatrixInput.java | 30 +++++++++++++++ ReverseString.java | 25 ++++++++++++ Tagless.java | 96 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 201 insertions(+) create mode 100644 ExtratFour.java create mode 100644 LinkedListed.java create mode 100644 MatrixInput.java create mode 100644 ReverseString.java create mode 100644 Tagless.java diff --git a/ExtratFour.java b/ExtratFour.java new file mode 100644 index 0000000..f7ebeb0 --- /dev/null +++ b/ExtratFour.java @@ -0,0 +1,26 @@ +import java.util.Scanner; + +public class ExtratFour { + public static void main(String[] args) { + lastFour(); + } + + public static void lastFour() { + + Scanner sc = new Scanner(System.in); + System.out.println("Please enter your text"); + String text = sc.next(); + sc.close(); + System.out.println(""); + char[] four = text.toCharArray(); + for (int i = 0; i < four.length; i++) { + System.out.print(four[i] + "\t"); + } + System.out.println(""); + int size = four.length; + int edge = size - 4; + for (int i = edge; i < size; i++) { + System.out.print(four[i] + "\t"); + } + } +} diff --git a/LinkedListed.java b/LinkedListed.java new file mode 100644 index 0000000..1e2441f --- /dev/null +++ b/LinkedListed.java @@ -0,0 +1,24 @@ +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * LinkedListed + */ +public class LinkedListed { + + public static void main(String[] args) { + Map linkHashMap = new LinkedHashMap<>(); + + linkHashMap.put("AMD", 8); + linkHashMap.put("Apple", 12); + linkHashMap.put("Intel", 10); + System.out.println("Our hashlinkedMap is: " + linkHashMap); + // get the value of a key in a hashlinkedMap + System.out.println("The CPU cores on AMD is: " + linkHashMap.get("AMD")); + + for (Map.Entry entry : linkHashMap.entrySet()) { + System.out.println(entry.getKey() + " " + entry.getValue()); + } + + } +} diff --git a/MatrixInput.java b/MatrixInput.java new file mode 100644 index 0000000..a88fcb2 --- /dev/null +++ b/MatrixInput.java @@ -0,0 +1,30 @@ +import java.util.ArrayList; +import java.util.Scanner; + +/** + * MatrixInput + */ +public class MatrixInput { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("Please enter the 2D Array here: "); + System.out.println("Numbers of rows: "); + int rows = sc.nextInt(); + System.out.println("Numbers of columns: "); + int columns = sc.nextInt(); + int[][] arr = new int[rows][columns]; + for (int i = 0; i < rows; i++) { + for (int j = 0; j < columns; j++) { + arr[i][j] = sc.nextInt(); + } + } + System.out.println(""); + for (int i = 0; i < rows; i++) { + for (int j = 0; j < columns; j++) { + System.out.print(arr[i][j]); + } + System.out.println(); + } + } +} diff --git a/ReverseString.java b/ReverseString.java new file mode 100644 index 0000000..0d44448 --- /dev/null +++ b/ReverseString.java @@ -0,0 +1,25 @@ +import java.util.Scanner; + +/** + * ReverseString + */ +public class ReverseString { + + public static void main(String[] args) { + + System.out.println(UserString()); + } + + private static String UserString() { + + Scanner sc = new Scanner(System.in); + System.out.println("Please enter your input here: "); + String userInput = sc.nextLine(); + + String revStr = ""; + for (int i = userInput.length() - 1; i >= 0; i--) { + revStr += userInput.charAt(i); + } + return revStr; + } +} diff --git a/Tagless.java b/Tagless.java new file mode 100644 index 0000000..8b7c573 --- /dev/null +++ b/Tagless.java @@ -0,0 +1,96 @@ +import java.util.Scanner; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Tagless + * In a tag-based language like XML or HTML, contents are enclosed between a + * start tag and an end tag like contents. Note that the + * corresponding end tag starts with a /. + * + * Given a string of text in a tag-based language, parse this text and retrieve + * the contents enclosed within sequences of well-organized tags meeting the + * following criterion: + * + * The name of the start and end tags must be same. The HTML code + *

Hello World

is not valid, because the text starts with an h1 tag and + * ends with a non-matching h2 tag. + * + * Tags can be nested, but content between nested tags is considered not valid. + * For example, in + *

contentsinvalid

, contents is valid but invalid is not valid. + * + * Tags can consist of any printable characters. + * + * Input Format + * + * The first line of input contains a single integer, + * (the number of lines). + * The + * + * subsequent lines each contain a line of text. + * + * Constraints + * + * Each line contains a maximum of + * printable characters. + * The total number of characters in all test cases will not exceed + * + * . + * + * Output Format + * + * For each line, print the content enclosed within valid tags. + * If a line contains multiple instances of valid content, print out each + * instance of valid content on a new line; if no valid content is found, print + * None. + * + * Sample Input + * + * 4 + *

Nayeem loves counseling

+ *

+ *

Sanjay has no watch

So wait for a while + * safat codes like a ninja + * Imtiaz has a secret crush + * + * Sample Output + * + * Nayeem loves counseling + * Sanjay has no watch + * So wait for a while + * None + * Imtiaz has a secret crush + * + */ +public class Tagless { + + public static String tags; + + public static void main(String[] args) { + + Scanner scanner = new Scanner(System.in); + int n = Integer.parseInt(scanner.nextLine()); + for (int i = 0; i < n; i++) { + String line = scanner.nextLine(); + Taglesstags(line); + } + scanner.close(); + } + + private static void Taglesstags(String line) { + String tagPattern = "<([^>]+)>([^<>]+)"; + Pattern pattern = Pattern.compile(tagPattern); + Matcher matcher = pattern.matcher(line); + boolean found = false; + + // let's loop through all the lines + while (matcher.find()) { + System.out.println(matcher.group(2)); + found = true; + } + if (!found) { + System.out.println("None"); + } + } +}