Advertisement
Guest User

ElectronicMessage

a guest
Nov 4th, 2022
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ElectronicMessage {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String input = scanner.nextLine();
  7.         String[] inputArr = input.split("");
  8.         String s = "";
  9.         char[] letters = new char[inputArr.length - 1];
  10.         for (String n : inputArr) {
  11.             s += n;
  12.         }
  13.         letters = s.toCharArray();
  14.  
  15.         char[] check = {' ','a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
  16.         int foundCount = 0;
  17.         int notFound = 0;
  18.         int sequence = 0;
  19.  
  20.         for (int i = 0; i < inputArr.length - 1; i++) {
  21.             boolean isFound = false;
  22.             for (int j = 0; j < check.length; j++) {
  23.                 if (letters[i] == check[j]) {
  24.                     isFound = true;
  25.                     break;
  26.                 }
  27.             }
  28.  
  29.             if (!isFound) {
  30.                 notFound++;
  31.             } else if (isFound && notFound > sequence) {
  32.                 sequence = notFound;
  33.                 notFound = 0;
  34.             }
  35.  
  36.             if (i == inputArr.length - 2 && sequence == 0) {
  37.                 sequence = notFound;
  38.                 notFound = 0;
  39.             }
  40.  
  41.             if (isFound) {
  42.                 notFound=0;
  43.             }
  44.         }
  45.         System.out.println(sequence);
  46.  
  47.     }
  48. }
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement