Skip to content

Instantly share code, notes, and snippets.

@AtharvaVaidya
Created October 1, 2016 02:56
Show Gist options
  • Save AtharvaVaidya/c381a05e7732735046360f691d2b5490 to your computer and use it in GitHub Desktop.
Save AtharvaVaidya/c381a05e7732735046360f691d2b5490 to your computer and use it in GitHub Desktop.
import java.util.*;
import java.util.ArrayList;
import java.util.Scanner;
public class lb
{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter input string: ");
String inputString = input.next();
System.out.print("Enter flag character: ");
String flagCharacter = input.next();
Boolean validInput = false;
for (int i = 0; i < inputString.length(); i++) {
if (Character.isUpperCase(inputString.charAt(i))) {
validInput = true;
} else {
System.out.print("Bad input.");
}
}
for (int i = 0; i < flagCharacter.length(); i++)
{
if (flagCharacter.charAt(i) == '$' || flagCharacter.charAt(i) == '#' || flagCharacter.charAt(i) == '*' || flagCharacter.charAt(i) == '&')
{
continue;
}
else {System.out.print("BAD INPUT BRUH");}
}
char repeatedLetter = inputString.charAt(0);
if (validInput) {
int counter = 0;
for (int i = 0; i < inputString.length(); i++) {
if (repeatedLetter == (inputString.charAt(i))) {
counter++;
repeatedLetter = inputString.charAt(i);
} else {
if (counter > 3) {
System.out.print(flagCharacter + repeatedLetter + counter);
} else {
for (int j = counter; j > 0; j--) {
System.out.print(repeatedLetter);
}
}
repeatedLetter = inputString.charAt(i);
counter = 1;
}
}
if (counter > 3) {
System.out.print(flagCharacter + repeatedLetter + counter);
} else {
for (int j = counter; j > 0; j--) {
System.out.print(repeatedLetter);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment