【Codeforces 158C】Cd and pwd commands
【链接】 我是链接,点我呀:)
【题意】
让你实现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的更多相关文章
- 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 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 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 ...
- 【codeforces 514D】R2D2 and Droid Army
[题目链接]:http://codeforces.com/contest/514/problem/D [题意] 给你每个机器人的m种属性p1..pm 然后r2d2每次可以选择m种属性中的一种,进行一次 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- css list menu
选择让page和folder都显示出来
- geronimo
时间限制 1s 空间限制 512MB 3.1 题目描述 "Geronimo∼" 时间还很多,让我们慢慢来. 不如听首开心的歌再看题?-- 算了,直接看题吧. 给定一个整数 n,以及 ...
- Flink之Window Operation
目录 Configuring Time Characteristics Process Functions Window Operators Applying Functions on Windows ...
- input的type等于mage标签引发的页面提交!
主要原因是使用了<input type="image",而且放在了<form中. <input type="image"标签类似<inp ...
- 湖南集训day4
难度:☆☆☆☆☆☆☆ 题解: 有个定理,另sum(x)表示小于等于x的数中与x互质的数的和 sum(x)=φ(x)*x/2 最后可知f(x)=x (f(1)=2) 当然打表能知道. 然后就转 ...
- Codeforces 763A
乍看之下感觉有点无从下手,,其实是个很简单的水题,陷入僵局 题目大意:给一棵树,树上每个节点都染色,问能否取下一个节点,使得剩余所有子树上的点的颜色都相同.能输出YES和取下的节点编号,否则输出NO. ...
- 自己做的一个android 音视频播放器
欢迎大家下载: http://download.csdn.net/detail/q610098308/8504335
- Ubuntu下搭建repo服务器(三): 搭建Android repo服务器
1. 配置repo 1.1 下载git-repo.git(B端) mkdir -p ~/gitCfg cd ~/gitCfg git clone https://gerrit.googlesourc ...
- ResGen.exe”已退出,代码为2 问题处理
转载自 http://blog.sina.com.cn/s/blog_5f82a1060101d8tm.html 在64位的Windows 7下,用VS2010编译4.0以前的.Net项目会有问题. ...
- Python学习(一)-在VS上搭建开发环境
1.到官网下载最新Python 注意:虽然目前大部分应用是Python2写的,但Python3必定会成为以后的主流 不管选择学习哪个,了解pyhton2和pyhton3的差异是必须的 2.安装Pyth ...