以前的字符串题本来就弱。。2年不写就更弱了。嗯。留作教训

God Le is the most talented ACMer in the TJU-ACM team.

When he wants to open a file,he can just use his keyboard instead of using his mouse to click.

Why he can do this?Because he uses the cmd.exe. There are many commands in cmd.exe.But God Le is kind of lazy,so he just uses three commands to change the current directory.

"cd dir"(without quotes):put you in a subdirectory.For example,if you are in C:\Programs,typing cd Vim will put you in C:\Programs\Vim.

"Disk(like C,D,etc):"(without quotes):put you in the directory in that Disk that you are in most recently.For example,if you are in C:\Programs,typing D: and C: will put you in C:\Programs.(at the beginning,when you type Disk:,you will be in Disk:\).

"cd .."(without quotes):move you up one directory.So,if you are in C:\Programs\Vim,cd .. moves you to C:\Programs.

Because God Le is very smart,he won't go to the directory that is not existed. Now,given a sequence of commands,God Le wants to know the current directory.

One thing that you should know is that God Le's computer only have four disks C,D,E,F.

HINT I:The initial directory is C:\users\godle

HINT II:every subdirectory is only a string contains no more than 10 lower-case letters.

Input

There are mulit cases.Each case begins with an integer m(1 ≤ m ≤ 10^3)means the operations.Next there are m lines.Each line contains a command.

Output

For each command,print the current directory.You can get more hints from the sample.

Sample Input

5
cd ..
D:
cd ..
cd abc
C:

Sample Output

C:\users
D:
D:
D:\abc
C:\users

题目大意:就是读命令 执行  输出结果 很简单的模拟题

但要注意一下几点

1.Disk命令:  如果当前在 C:\zhou 进行1.D: 2. C: 命令后回到C:\zhou 而不是去C:\。

2.mulit case : 英语不好就这样被坑了。。结合样例以为只有一组数据 结果WA了N遍还不知悔改

3.反斜杠赋值要这样做  c='\\'

4.读了m后  还有一个换行符没读。如果用gets()读的话,记得用一次gets()把那个换行符给过滤掉

5.当然这题用 scanf("%s") 去处理似乎更加完美 详情见下面代码

6 活用 strcat strcmp strcat

上一下大牛代码仔细分析分析

<pre name="code" class="html"><pre name="code" class="cpp"><pre name="code" class="html"><pre name="code" class="cpp">#include<stdio.h>
#include<string.h> int main()
{
freopen("a.txt","r",stdin);
freopen("c.txt","w",stdout);
char str[4][20000];
char temp[20],dir[20];
int i,m,cur,j,len;
while(scanf("%d",&m)!=EOF)
{
cur=0;
strcpy(str[0],"C:\\users\\godle");
strcpy(str[1],"D:");
strcpy(str[2],"E:");
strcpy(str[3],"F:");
for(i=0;i<m;i++)
{
scanf("%s",temp);
if(strcmp(temp,"cd")==0)
{
scanf("%s",dir);
if(strcmp(dir,"..")==0)
{
len=strlen(str[cur]);
for(j=len-1;j>=0;j--)
if(str[cur][j]=='\\')
break;
if(j>=0)
str[cur][j]=0;
}
else
{
strcat(str[cur],"\\");
strcat(str[cur],dir);
}
}
if(strcmp(temp,"C:")==0)
{
cur=0;
}
if(strcmp(temp,"D:")==0)
{
cur=1;
}
if(strcmp(temp,"E:")==0)
{
cur=2;
}
if(strcmp(temp,"F:")==0)
{
cur=3;
}
printf("%s\n",str[cur]);
}
}
return 0;
}

十分优美的代码

因为多年没写 所以先解析基础知识



1.首先strcpy

原型声明:extern char *strcpy(char* dest, const char *src);
头文件:#include <string.h> 和 #include <stdio.h>
功能:把从src地址开始且含有NULL结束符的字符串复制到以dest开始的地址空间
说明:src和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串。
返回指向dest的指针
/**********************
*C语言标准库函数strcpy的一种典型的工业级的最简实现
*返回值:目标串的地址。
*对于出现异常的情况ANSI-C99标准并未定义,故由实现者决定返回值,通常为NULL。
*参数:des为目标字符串,source为原字符串
*/
 char*strcpy(char*des,constchar*source) {
 char*r=des;
 while(*des++=*source++);
 return;
 }
 /*while((*des++=*source++));的解释:赋值表达式返回左操作数,所以在复制NULL后,循环停止*/

2.strcmp

原型:extern int strcmp(const char *s1,const char * s2);
所在头文件:string.h
功能:比较字符串s1和s2。
一般形式:strcmp(字符串1,字符串2)
说明:
当s1<s2时,返回为负数
当s1=s2时,返回值= 0
当s1>s2时,返回正数
即:两个字符串自左向右逐个字符相比(按ASCII值大小相比较),直到出现不同的字符或遇'\0'为止。如:
"A"<"B" "a">"A" "computer">"compare"
最正宗的源码
/*strcmpfunction*/
#include<string.h>I
int(strap)(constchar*sl,constchar*s2)
{/*compareunsignedcharsl[],s2[]*/
for(;*sl==*s2;++sl,++s2)
if(*sl=='\O')
return(0);
return((*(unsignedchar*)sl<*(unsignedchar*)s2)?-1:+1);
}

3.strcpy

原型

extern char *strcat(char *dest,char *src);

用法

#include <string.h>

在C++中,则存在于<cstring>头文件中

功能

把src所指字符串添加到dest结尾处(覆盖dest结尾处的'\0')并添加'\0'。

说明

src和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串。

返回指向dest的指针

char*strcat(char*strDest,constchar*strSrc)
{
char*address=strDest;
while(*strDest)
strDest++; while(*strDest++=*strSrc++)
{}
return address;
}

仔细分析分析这道字符串题代码

很容易发现这类题目函数scanf ()的奇妙运用比Gets()好很多利用string的函数更是完美。

字符串的题目就是要多模仿代码。

上我丑陋的代码了

#include<stdio.h>
char A[101];
char s[5][1010];
int temp[5],d=0;
int main()
{
freopen("a.txt","r",stdin);
freopen("b.txt","w",stdout);
int n=0,i=0,j=0,t=0,x=0,z=0;
while(scanf("%d",&n)>0)
{
i=0,j=0,t=0,x=0,z=0,d=0;
memset(temp,0,sizeof(temp));
memset(s,0,sizeof(s));
temp[0]=2;
strcpy(s[0],"C:\\users\\godle");
strcpy(s[1],"D:");
strcpy(s[2],"E:");
strcpy(s[3],"F:"); gets(A);
for(i=1;i<=n;i++)
{
memset(A,0,sizeof(A));
gets(A);
if(A[0]=='c'&&A[1]=='d')
if(A[3]=='.')
{
t=0;x=0;
if (temp[d]==0) {printf("%c%c",s[d][0],s[d][1]); printf("\n");}
else {
temp[d]=temp[d]-1;
for(t=0;t<=temp[d];x++)
{
if(s[d][x]=='\\') t++;
if(t<=temp[d]) printf("%c",s[d][x]);
}
s[d][x-1]=0;
printf("\n");
}
}
else
{
temp[d]=temp[d]+1;
for(x=0;s[d][x]!=0;x++)
printf("%c",s[d][x]);
s[d][x]='\\';x++;z=x-1;
for(t=3;A[t]!=0;t++,x++)
s[d][x]=A[t];
s[d][x]=0;
for(x=z;s[d][x]!=0;x++)
printf("%c",s[d][x]);
printf("\n");
}
else
{
if(A[0]=='C') d=0;
else if(A[0]=='D') d=1;
else if(A[0]=='E') d=2;
else if(A[0]=='F') d=3;
for(x=0;s[d][x]!=0;x++)
printf("%c",s[d][x]);
printf("\n");
}
}
}
return 0;
}



教训:TOJ[4081] God Le wants to know the directory的更多相关文章

  1. 【转】DCC32的参数详解

    完整的内容如下: // DCC32编译器的设置说明. // Dcc32 [options] filename [options] // DCC32 [操作选项] 文件名称 [操作选项] // -A&l ...

  2. 关于要python爬虫你需要的一些网址和信息[待补充]

    phantomjs无头浏览器(基本不用) http://phantomjs.org/download.html 如果报 下面这种错误 [root@hwgz01 ~]# phantomjs phanto ...

  3. Le lié à la légèreté semblait être et donc plus simple

    Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...

  4. 新人入职100天,聊聊自己的经验&教训

    这篇文章讲了什么? 如题,本屌入职100天之后的经验和教训,具体包含: 对开发的一点感悟. 对如何提问的一点见解. 对Google开发流程的吐槽. 如果你 打算去国外工作. 对Google的开发流程感 ...

  5. TOJ 2776 CD Making

    TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性...  贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...

  6. LVM原理及PV、VG、LV、PE、LE关系图

    PV(physical volume):物理卷在逻辑卷管理系统最底层,可为整个物理硬盘或实际物理硬盘上的分区.VG(volume group):卷组建立在物理卷上,一卷组中至少要包括一物理卷,卷组建立 ...

  7. android socket编程用Bufferreader读取的一个失败教训

    由于我的手机需要用笔记本开的wifi,躺在床上玩手机时需要关电脑或者是要让电脑放歌的时候总是不想下床,于是我想能不能用一个APP,然后通过局域网实现在手机上对电脑进行操控呢?说干就干. 我在电脑上用的 ...

  8. Redis简介、与memcached比较、存储方式、应用场景、生产经验教训、安全设置、key的建议、安装和常用数据类型介绍、ServiceStack.Redis使用(1)

    1.NOSQL简介 nosql的产生并不是要彻底的代替关系型数据库,而是作为传统关系型数据库的一个补充. Facebook和360使用Cassandra来存储海量社交数据 Twitter在其url抓取 ...

  9. android4.3 Bluetooth(le)分析之startLeScan分析

    BluetoothAdapter.java中有low enery(le)的一些方法,android提供了这些方法,但源码中并未找到这些方法的调用之处.本文档主要分析这类方法的执行流程,来了解下le到底 ...

随机推荐

  1. WEB服务器5--IIS中ISAPI扩展、ISAPI筛选器

    在IIS的文档中经常会提到两个术语:ISAPI扩展和ISAPI筛选器. ISAPI扩展 “ISAPI扩展(ISAPI Extension)”是一种可以添加到IIS中以增强Web服务器功能的程序,其载体 ...

  2. Silverlight Application 无法调用js的方法

    今天下午做项目的时候遇到了这个错误 找了很多原因没找出,在蛋疼之际找出了问题, Silverlight调js方法的时候 js方法里面不能出现一点问题,如果有一点问题就会报这个错误.

  3. C#中的委托和游戏中的运用

    C#中的委托与游戏中的运用 1.什么是委托 在C/C++中,有函数指针的概念,即指向函数的指针.当我们调用该指针时,就相当于调用了该指针所指向的函数,这就是函数指针的一个作用,而他另一个作用就是将自己 ...

  4. OpenGL ES 2.0 shader开发

    1.创建一个shader容器 GLES20.glCreateShader(shaderType); 函数原型为: int glCreateShader (int type) 方法参数: GLES20. ...

  5. tomcat解决乱码

    今天遇到个问题,太尴尬了: 本来做好并测试号的项目提交到svn, 组员下了之后,又部分url传递的中文参数在另一个jsp接收出现乱码(只有我的不乱码). 改了之后更尴尬的事情发生了:组员的全部不乱码, ...

  6. ajax创建对象

    <script>     function createAjax(){         var request=false;                   //window对象中有X ...

  7. winform 窗口点击窗体任意位置移动窗体

    private bool _isDown; private Point _mousePoint; private void Users_MouseDown(object sender, MouseEv ...

  8. wordpress教程之在非single.php页面调用文章的信息

    使用Wordpress的朋友可能遇到这样的问题,在非single.php页面中我们有时候想要调用当前文章的标题.内容等信息,而Wordpress在生成文章页的时候在各个页面中唯一不变的只有当前的文章I ...

  9. NOI十连测 第四测 T3

    思路: 算法一:可以n^2找出每个点的权值,然后n^2做完,预计得分10 算法二:随机找点然后每次找最高..貌似只有10分?然而考试的时候煞笔了,边界设成inf.. 算法三:随机找几个点,然后随机爬山 ...

  10. USB系列之八:透过ASPI执行SCSI命令

    在<USB系列之七>里我们介绍了ASPI的规范,并对一系列ASPI的命令做了测试,其中的02号命令是执行SCSI命令,我们专门在这篇文章中介绍,在<USB系列七>中,我们已经了 ...