https://scut.online/p/240

就是要小心绝对路径中也有.和..出现。

#include<bits/stdc++.h>
using namespace std;
#define ll long long struct path{
string fullpath;
void toparent(){
int n;
n=fullpath.length();
for(int i=n-;i>=;i--){
if(fullpath[i]=='/'){
fullpath=fullpath.substr(,i);
if(fullpath=="")
fullpath="/";
return;
}
}
} void tonext(string ne){
if(ne==".")
return;
else if(ne==".."){
toparent();
return;
}
else{
if(fullpath!="/")
fullpath+=(string)("/"+ne);
else{
fullpath+=(string)(ne);
}
}
}
}; int main(){
int n;
while(cin>>n){
string cd,s;
path cur;
cur.fullpath="/";
while(n--){
cin>>cd>>s;
int i=;
if(s[]=='/'){
cur.fullpath="/";
i=;
}
{
s+='/';
string tt;
for(;i<s.length();i++){
if(s[i]!='/'){
tt+=s[i];
}
else{
cur.tonext(tt);
tt="";
}
}
} }
cout<<cur.fullpath<<endl;
}
}

最新文章

  1. 2016/12/31_Python
  2. Spring Security笔记:Remember Me(下次自动登录)
  3. Overlay network 覆盖网络
  4. MySQL常用的自带函数
  5. PHP用substr截取字符串出现中文乱码问题用mb_substr
  6. pku 1703(种类并查集)
  7. Apache2.2+Tomcat7.0整合配置详解
  8. 悟透Javascript undefined,null,&quot;&quot;,0这四个值转换为逻辑值时就是false &amp;this关键字
  9. 【iOS开发之C语言】sprintf,strncpy,strcmp三个函数的区别
  10. 用getBoundingClientRect()来获取页面元素的位置
  11. 关于目前自己iOS项目使用的第三方开源库
  12. 异步请求取得json数据
  13. JAVA的入门代码
  14. C#如何在生成文件夹或者文件时候自动重命名
  15. AC自动机——1 Trie树(字典树)介绍
  16. ORA-01017: invalid username/password; logon denied 解决方案
  17. django实现类似触发器的效果
  18. mybatis column 和property
  19. c#day04从控制台获取一个字符
  20. effective C++学习一(仅供个人学习记录,本文摘录effective C++)

热门文章

  1. oracle下session的查询与删除
  2. 协议的注冊与维护——ndpi源代码分析
  3. saltstack源码安装
  4. backtrace、backtrace_symbols、backtrace_symbols_fd-support for application self-debugging
  5. 浅谈JavaScript的函数表达式(递归)
  6. C语言的一些特殊使用方法————————【Badboy】
  7. visual studio 2013 update 3正式版出来了
  8. Java 线程池ThreadPoolExecutor简单应用
  9. UOJ #35. 后缀排序[后缀数组详细整理]
  10. using the flume-ng-sql-source plugin to push data from Mysql DB to Spark