STRMAN Editorial

https://www.codechef.com/TIUC2020/problems/STRMAN

PROBLEM LINK:

[Practice] https://www.codechef.com/TIUC2020/problems/STRMAN
[Contest] https://www.codechef.com/TIUC2020/problems/BINARYST

Author: Aishik Kirtaniya(https://www.codechef.com/users/aishik212)
Tester: Tester’s name
Editorialist: Editorialist’s name

DIFFICULTY:

SIMPLE-EASY

PREREQUISITES:

Loops, Regex, Arrays

PROBLEM:

You are required to remove all the characters from the input string where the length of string is less than 10000000 characters and out the final length of the string. That is the final String should only contain characters from a−za−z and A−ZA−Z. Then Print a String which should only print the Unique Characters of the string and in the same order as the modified string.

QUICK EXPLANATION:

Remove Non English Alphabet and count the total length of the final string.
Then only print the unique letters in the same way as arranged bin the string.

EXPLANATION:

You are required to remove all the characters from the input string where the length of string is less than 10000000 characters and out the final length of the string. That is the final String should only contain characters from a−za−z and A−ZA−Z. Then Print a String which should only print the Unique Characters of the string and in the same order as the modified string.
For example
A String contains acbddcaa123 first remove anything other than a−za−z & A−ZA−Z
The string would become acbddcaa
Now print the length of this string that is 8
Then only print the unique characters in the same order as the String
The string would become acbd
therefore final output will be
8
acbd
Print BLANK if length obtained is 0
Note: that Uppercase and Lowercase alphabets should be treated as different characters

ALTERNATE EXPLANATION:

Sample Input
asdd
asd;;ads
1232412
asda123.//.
adjhghagjdshgbbcc
Sample Output
4
asd
6
asd
0
BLANK
4
asd
17
adjhgsbc

SOLUTIONS:

Regex Solution

String final_s;
final_s = (input.replaceAll("[^a-zA-Z]", “”).replaceAll(" “,”"));
System.out.println(final_s.length());
//System.out.println(characters.toString().replaceAll("[\[\], ]",""));
//regex
List c = new ArrayList<>();
for(int i = 0;i < final_s.length();i++)
{
char s = final_s.charAt(i);
if(c.size() <= 52)
{
if(c.indexOf(s) == -1)
{
c.add(s);
System.out.print(s);
}
}else
{
i = final_s.length();
}
}
System.out.println();
}

Brute Force Solution

Scanner scanner = new Scanner(System.in);
String input = scanner.next();

StringBuilder final_s = new StringBuilder();
List characters = new ArrayList<>();
for (int i = 0; i < input.length(); i++) {
int x = input.charAt(i);
if ((x >= 97 && x <= 122) || (x >= 65 && x <= 90)) {
char x1 = (char) x;
final_s.append(x1);
if (characters.indexOf(x1) == -1) {
characters.add(x1);
}
}
}
System.out.println(final_s.length());
for (char s : characters) {
System.out.print(s);
}