Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Objects;
- import java.util.SortedSet;
- import java.util.TreeSet;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author Ossu
- */
- class DNAString {
- private final static Character[] DATASET = {'A', 'C', 'G', 'T'};
- private final static int MIN_RANGE = 0;
- private final static int MAX_RANGE = 1000;
- private final static String INVALID_CHAR = "Invalid input,not matched with dataset";
- private final static String CHAR_LENGTH_EXCEEDS = "Input does not allow to be exceeds more than " + MAX_RANGE + " characters";
- private static String returnFinalComplement(String reverseStr) {
- StringBuilder finalStr = new StringBuilder();
- for (char c : reverseStr.toCharArray()) {
- finalStr.append(
- c == 'G' ? 'C'
- : c == 'C' ? 'G'
- : c == 'T' ? 'A'
- : c == 'A' ? 'T'
- : c
- );
- }
- return finalStr.toString();
- }
- // char[] charlist = list.toCharArray();
- // for (int i = 0; i < charlist.length; i++) {
- // switch (charlist[i]) {
- // case 'A': {
- // charlist[i] = 'T';
- // }
- // break;
- // case 'T': {
- // charlist[i] = 'A';
- // }
- // break;
- // case 'G': {
- // charlist[i] = 'C';
- // }
- // break;
- // case 'C': {
- // charlist[i] = 'G';
- // }
- // break;
- // }
- // }
- // return new String(charlist);
- //
- // }
- public static boolean validateInput(String input) {
- List<Character> chars = new ArrayList<>();
- for (char c : input.toCharArray()) {
- chars.add(c);
- }
- boolean result = false;
- SortedSet<Character> mySet = new TreeSet<>(chars);
- for (int i = 0; i <= mySet.size();) {
- for (Character c : mySet) {
- result = Objects.equals(c, DATASET[i]);
- i++;
- if (!result) {
- break;
- }
- }
- if (result) {
- return result;
- } else {
- break;
- }
- }
- return result;
- }
- public static String reverseIt(String source) {
- int i, len = source.length();
- StringBuilder dest = new StringBuilder(len);
- for (i = (len - 1); i >= 0; i--) {
- dest.append(source.charAt(i));
- }
- return dest.toString();
- }
- public static void main(String[] args) throws IOException {
- BufferedReader readInput = new BufferedReader(new InputStreamReader(System.in));
- String source = readInput.readLine();
- if (source.length() > MIN_RANGE && source.length() <= MAX_RANGE) {
- boolean validateInput = validateInput(source);
- if (validateInput) {
- // String reverseString = reverseIt(source);
- String reverseString = reverseIt(source);
- System.out.println(returnFinalComplement(reverseString));
- // String revereStringComplement = returnFinalComplement(reverseString);
- } else {
- System.out.println(INVALID_CHAR);
- }
- } else {
- System.out.println(CHAR_LENGTH_EXCEEDS);
- }
- }
- }
Add Comment
Please, Sign In to add comment