import java.text.*;
import java.util.*;
public class Main{ public static void main(String[]ags){ Scanner in = new Scanner(System.in); String a=in.nextLine(); System.out.println(simplifyPath(a)); } public static String simplifyPath(String path) { if(path.length() == 0){ return path; } String[] splits = path.split("/"); LinkedList<String> stack = new LinkedList<String>(); for (String s : splits) { if(s.length()==0 || s.equals(".")){ continue; }else if(s.equals("..")){ if(!stack.isEmpty()){ stack.pop(); } }else{ stack.push(s); } } if(stack.isEmpty()){ stack.push(""); } String ret = ""; while(!stack.isEmpty()){ ret += "/" + stack.removeLast(); } return ret; }
}
第一题
#搜狐#