好代码就是用来欣赏的--喵呜代码
/*
膜拜喵呜秒杀了我花了3个小时码的代码
以下是鄙人的注释
*/
#include <stdio.h>
#include <string.h>
char ans[1000][205];//二维数组
char str[10005];//存cd情况下的字符串
char tmp[10005];
int up;
void Print()
{
int i;
printf("/");
for (i=0;i<up;i++)
{
printf("%s",ans[i]);
}
printf("\n");
}
void Add()
{
// printf("%s----------\n",tmp);
if (tmp[0]=='.')
VK Cup 2012 Qualification Round 1--C. Cd and pwd commands
{
up--;//删除上一行,将未来的新字符串覆盖它
}
else
{
strcpy(ans[up],tmp);//ans[][]是个二维数组。up会增加,即指针会向下一行移动。
up++;
}
}
int main()
{
int i,j,n,now;
up=0;
scanf("%d",&n);
while(n--)
{
// printf("%d\n",up);
scanf("%s",str);
if (str[0]=='p')
{
Print();
}
else
{
scanf("%s",str);
now=0;
i=0;
if (str[0]=='/') {up=0;i=1;}//如果输入的字符串第一个有/,就从下一个字符开头复制字符串,复制到tmp
for (;i<strlen(str);i++)
{
tmp[now++]=str[i];//此时now已经超过str【i】的长度(就输入一个字符哦)
if (str[i]=='/')//遇到下一个斜杠
{
tmp[now++]='\0';//后面加上结束字符
Add();//tmp里面存入的单词或“.”
now=0;//归零,便于下一次计数
}
}
tmp[now++]='/';
tmp[now++]='\0';
Add();
now=0;
}
}
return 0;
}