Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class lqlq {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String password= scanner.nextLine();
- String commands= scanner.nextLine();
- String newRawPassword="";
- while (!commands.equals("Done")){
- String[]input=commands.split("\\s+");
- String caseS=input[0];
- switch (caseS){
- case"TakeOdd":
- for(int i=0;i<=password.length()-1;i++){
- if(i%2!=0){
- String currentChar=""+password.charAt(i);
- newRawPassword=newRawPassword+currentChar;
- }
- }
- System.out.println(String.format(newRawPassword));
- break;
- case"Cut":
- int index=Integer.parseInt(input[1]);
- int length=Integer.parseInt(input[2]);
- String subString=newRawPassword.substring(index,(index+length));
- newRawPassword=newRawPassword.replace(subString,"");
- System.out.println(String.format(newRawPassword));
- break;
- case"Substitute":
- String sString=input[1];
- String substitute=input[2];
- if (newRawPassword.contains(sString)) {
- while (newRawPassword.contains(sString)) {
- newRawPassword = newRawPassword.replace(sString, substitute);
- }
- System.out.println(String.format(newRawPassword));
- }else{
- System.out.println(String.format("Nothing to replace!"));
- }
- break;
- }
- commands= scanner.nextLine();
- }
- System.out.println(String.format("Your password is: %s",newRawPassword));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement