Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 80 of 100 pts :(
- import java.util.Scanner;
- import java.util.Arrays;
- public class Problem3 {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String inputString = scan.nextLine();
- String testString = inputString.replace(" ","").replace("(", " (").trim();
- String[] noSpaces = testString.split(" ");
- String[] noBrackets = new String[noSpaces.length];
- int[] numArray = new int[noSpaces.length];
- int[] maxNumberOfSeq = new int[numArray.length];
- for (int i = 0; i < noSpaces.length; i++) {
- // System.out.print(noSpaces[i] + ",");
- noBrackets[i] = noSpaces[i].replace('(', ' ').replace(')', ' ')
- .trim();
- numArray[i] = Integer.parseInt(noBrackets[i]);
- }
- int count = 1;
- int j=0;
- for (int i = 0; i < numArray.length-1; i++) {
- if(inSequence(numArray[i], numArray[i+1])){
- count++;
- }else{
- count=1;
- }
- j++;
- maxNumberOfSeq[j]= count;
- }
- // for (int i = 0; i < maxNumberOfSeq.length; i++) {
- // System.out.println(maxNumberOfSeq[i]);
- // }
- Arrays.sort(maxNumberOfSeq);
- System.out.println(maxNumberOfSeq[maxNumberOfSeq.length-1]);
- }
- static boolean inSequence(int number1, int number2) {
- if (number1 == 0 || number2 == 0) {
- return true;
- } else if ((number1 % 2 == 0 && number2 % 2 != 0)
- || (number1 % 2 != 0 && number2 % 2 == 0)) {
- return true;
- } else {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement