【链接】 我是链接,点我呀:)

【题意】

让你实现Shell的cd和pwd操作

【题解】

用一个list表示当前的路径
如果路径以/开头则表示需要清空当前路径重新走路
否则在原来路径的基础上继续加就可以了

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = (int)3000;
static class Task{
ArrayList cwd= new ArrayList(); String getCWD() {
StringBuilder sb = new StringBuilder("/");
for (int i = 0;i < cwd.size();i++) {
String s = (String)cwd.get(i);
sb.append(s+"/");
}
return sb.toString();
} public void solve(InputReader in,PrintWriter out) {
int n;
n = in.nextInt();
for (int i = 1;i <= n;i++) {
String ope = in.next();
if (ope.equals(new String("pwd"))) {
out.println(getCWD());
}else {
String p = in.next();
String []parameters;
if (p.charAt(0)=='/') {
cwd.clear();
parameters = p.substring(1,p.length()).split("/");
}else {
parameters = p.split("/");
}
for (int j = 0;j < parameters.length;j++) { if (!parameters[j].equals("..")) {
cwd.add(parameters[j]);
}else {
cwd.remove((int)cwd.size()-1);
}
}
}
}
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
}
}
}

【Codeforces 158C】Cd and pwd commands的更多相关文章

  1. VK Cup 2012 Qualification Round 1 C. Cd and pwd commands 模拟

    C. Cd and pwd commands Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. VK Cup 2012 Qualification Round 1---C. Cd and pwd commands

    Cd and pwd commands time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  4. 【codeforces 514D】R2D2 and Droid Army

    [题目链接]:http://codeforces.com/contest/514/problem/D [题意] 给你每个机器人的m种属性p1..pm 然后r2d2每次可以选择m种属性中的一种,进行一次 ...

  5. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  6. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  7. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  8. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  9. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

随机推荐

  1. extern_c

    (1)    使用extern和包含头文件来引用函数有什么区别呢?extern的引用方式比包含头文件要简洁得多!extern的使用方法是直截了当的,想引用哪个函数就用extern声明哪个函数.这大概是 ...

  2. setings.py配置文件详解

    BASE_DIR指的是项目的根目录.SECRET_KEY是安全码. # SECURITY WARNING: don't run with debug turned on in production! ...

  3. 对腾讯云服务器linux系统进行分区格式化操作

  4. PCB MS SQL 标量函数与表值函数(CLR) 实现文件与目录操作

    一.C#写SQL SERVER(CLR)实现文件操作 标量函数: 文件移动 ,复制,检测文件存在,写入新文件文本,读取文本,创建目录,删除目录,检测目录是否存在 /// <summary> ...

  5. PCB Genesis脚本 C#调用Python

    在PCB行业,Genesis的二次开发的编程脚本越来越丰富了啊,从一开始进入眼界的Genesis脚本语言是很少的,CSH,PERL, 再后来慢慢发展,VB,易语言,VB.NET,C#,Java,TCL ...

  6. thinkphp结合云之讯做短信验证码

    thinkphp结合云之讯做短信验证码先去云之讯注册账号 网址http://www.ucpaas.com/ 注册云之讯平台账号,即可免费获得10元测试费用测试够用啦 解压附件到 ThinkPHP\Li ...

  7. 【USACO2009 Open】滑雪课程ski

    [USACO2009 Open]滑雪课程 Ski Lessons Time Limit: 1000 ms Memory Limit: 131072 KBytes Description 约翰请贝西去科 ...

  8. EasyUI系列学习(四)-Droppable(放置)

    一.创建组件 1.使用标签创建一个放置区 <div id="pox" class="easyui-droppable" style="width ...

  9. HashMap的尾部遍历问题--Tail Traversing

    在看网上HashMap的resize()设计时,提到尾部遍历.   JDK1.7的HashMap在实现resize()时,新table[]的列表采用LIFO方式,即队头插入.这样做的目的是:避免尾部遍 ...

  10. input获得焦点和失去焦点

    总结:placeholder因为在IE7 8 9 浏览器不支持所以没用它效果:当input获取光标的时候如果是默认提示则input内容为空.如果不是则为输入内容           当失去光标的时候, ...