Codeforces VK Cup 2012 Qualification Round 1 /158C (字符串处理)

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6



C. Cd and pwd commands



http://codeforces.com/problemset/problem/158/C



time limit per test



memory limit per test



input



output


cd (change the current directory) and pwd

/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".

cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.

pwd should display the absolute path to the current directory. This path must not contain "..".

cd


Input



n (1 ≤ n ≤ 50) — the number of commands.

n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter.

cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd

Directories in the file system can have the same names.


Output



pwd


Sample test(s)



input



7 pwd cd /home/vasya pwd cd .. pwd cd vasya/../petya pwd



output



/ /home/vasya/ /home/ /home/petya/



input



4 cd /a/b pwd cd ../a/b pwd



output



/a/b/ /a/a/b/


学英语:

The directory changes to the specified directory, starting from the current one.

从当前目录开始,变更到指定目录。


完整代码:


/*30ms,1000KB*/

#include<cstdio>
#include<cstring>

char com[4], str[5010][201], temp[201];///注意数组要开的大小!!

int main(void)
{
	int n, i = 0, j;
	char ch, *p;
	scanf("%d", &n);
	while (n--)
	{
		scanf("%s", com);
		if (com[0] == 'p') ///pwd
		{
			putchar('/');
			if (i)
			{
				for (j = 0; j < i; ++j)
				{
					printf("%s", str[j]);
					putchar('/');
				}
			}
			puts("");
		}
		else///cd
		{
			getchar();
			ch = getchar();
			if (ch == '/')
				i = 0;
			else if (ch == '.'){
					getchar();
					--i;
			}
            else
                ungetc(ch, stdin);
			gets(temp);
			if (p = strtok(temp, "/"))
			{
				strcpy(str[i], p);
				if (str[i][0] == '.')
					--i;
				else
					++i;
			}
			while (p = strtok(NULL, "/"))
			{
				strcpy(str[i], p);
				if (str[i][0] == '.')
					--i;
				else
					++i;
			}
		}
	}
	return 0;
}




阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

“Codeforces VK Cup 2012 Qualification Round 1 /158C (字符串处理)” 的相关文章

快速入门

下划线(_)在解释器中表示最后一个表达式的值 raw_input user = raw_input('Enter login name:') print 'you login is:%s' % user num = raw_input("Input a nu...

list

> (define x (list 1 2 3)) > x '(1 2 3) > (define y (list 4 5 6)) > (append x y) '(1 2 3 4 5 6) > (cons x y) '((1 2 3) 4 5 6) > (list...

php数据库如何修改字段位置 - 编程语言

本文小编为大家详细介绍“php数据库如何修改字段位置”,内容详细,步骤清晰,细节处理妥当,希望这篇“php数据库如何修改字段位置”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。 首先,我们需要连接到数据库。在连接到...

「SQL面试题库」 No

1、专栏介绍 「SQL面试题库」是由 不是西红柿 发起全员免费参与的SQL学习活动。我每天发布1道SQL面试真题从简单到困难涵盖所有SQL知识点我敢保证只要做完这100道题不仅能轻松搞定面试代码能力和工作效率也会有明显提升。 1.1 活动流程 整理题目西红柿每天无论刮风下雨保证...

ChatGPT微信小程序怎么搭建 - 开发技术

这篇“ChatGPT微信小程序怎么搭建”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“ChatGPT微信小程序怎么搭建”文章吧。要搭建一个ChatGPT微...

chatGPT国内中文版免费下载的方法是什么 - 开发技术

这篇文章主要介绍“chatGPT国内中文版免费下载的方法是什么”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“chatGPT国内中文版免费下载的方法是什么”文章能帮助大家解决问题。ChatGPT软件介绍ChatGPT以对话方式进...