# include <stdio.h>
# include <string>
# include <cstring>
# include <iostream>
using namespace std;
int main ()
{
string a,p="/",temp;
int n,i,k;
scanf("%d",&n);
while(n--)
{
cin>>a;
if(a=="cd")
{
cin>>a;
a+='/';
for(i=0;i<a.length ();i++)
{
temp+=a[i];
if(a[i]=='/')
{
if(temp=="/")
{
p=temp;
}
else if(temp=="../")
{
for(k=p.length ()-1;p[k-1]!='/';k--)
;
p.resize(k);
}
else
{
p+=temp;
}
temp="";
}
}
}
else
cout<<p<<endl;
}
return 0;
}
C++语言的有点麻 就是你定义数组的时候不需要考虑长度的问题神马的 貌似用的是链表之类的 这个程序里面有string的定义 还有一个.length() 和.resize() 可以使用 这题如果用C还是挺麻烦的
Codeforces 158C - Cd and pwd commands
最新推荐文章于 2019-02-12 19:48:00 发布