Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> f(3)
- 0010111
- >>> f(3)
- 0123456789876543210
- >>> f(3)
- 001010011110111
- import java.util.Scanner;
- import java.util.ArrayList;
- public class Checker {
- public static void main(String[] args) throws Exception {
- int substringLength = Integer.parseInt(args[0]);
- Scanner sc = new Scanner(System.in);
- sc.useDelimiter("");
- ArrayList<Character[]> active = new ArrayList<Character[]>();
- Character[] current = new Character[substringLength],
- compare, prev;
- for (int i = 0; i < substringLength; i++) {
- current[i] = sc.next().charAt(0);
- }
- for (int index = 0; sc.hasNext(); index++) {
- for (int k = 0; k < index; k++) {
- boolean differ = false;
- compare = active.get(k);
- for (int j = 0; j < substringLength; j++) {
- differ = differ || compare[j].compareTo(current[j]) != 0;
- }
- if (!differ)
- throw new Exception("Match found for subset " + index);
- }
- active.add(current);
- prev = current;
- current = new Character[substringLength];
- for (int k = 1; k < substringLength; k++) {
- current[k - 1] = prev[k];
- }
- current[substringLength - 1] = sc.next().charAt(0);
- }
- System.out.println("Input is a valid version series.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement