路径加密

image-20240412140215066

class Solution {
    public String pathEncryption(String path) {
        StringBuilder b = new StringBuilder();
        for(char c : path.toCharArray()){
            if(c == '.') b.append(' ');
            else b.append(c);
        }
        return b.toString();
    }
}

字符串单词翻转

image-20240412140544176

import java.util.*;
class Solution {
    public String reverseMessage(String message) {
        Stack<String> l = new Stack();
        
        for(String s1 : message.split(" ")){
            if(!s1.isBlank())
                l.push(s1);
        }
        if(l.empty()) return "";        //记得判断空嘞
        StringBuilder s = new StringBuilder(l.pop());
        while(!l.empty()){
            s.append(' ');
            s.append(l.pop());
        }   
        String ans = s.toString();
        return ans;
    }
}

动态口令

image-20240412140754042

class Solution {
    public String dynamicPassword(String password, int target) {
        StringBuilder s =  new StringBuilder();
        s.append(password.substring(target,password.length()));
        s.append(password.substring(0, target));
        return s.toString();
    }
}