原题地址:http://acm.uestc.edu.cn/#/problem/show/327

The new operating system BerOS has a nice feature. It is possible to use any number of characters / as
a delimiter in path instead of one

traditional /.
For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are
equivalent. The character / (or some

sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as

single character /.

A path called normalized if it contains the smallest possible number of characters /.

Your task is to transform a given path to the normalized form.

Input

There are multi-cases. The first line of each case contains only lowercase Latin letters and character / —
the path to some directory. All paths

start with at least one character /.
The length of the given line is no more than 100 characters,
it is not empty.

Output

The path in normalized form.

Sample input and output

Sample Input Sample Output
//usr///local//nginx/sbin
/usr/local/nginx/sbin

题目大意是将路径化为linux下的最简格式,即目录间由一个斜杠隔开,根目录前有一个斜杠。说白了就是将多个斜杠变为一个。


此题可以使用常规思路,利用开关变量,不断判断是否为字母,然后整个单词输出。但是,巧妙利用C++的流处理,能非常简单的处理这道题。 首先
,需要声明库<sstream>,这是处理字符串流的库。然后创建一个输入流isstream
is(s)
(注意,这里的输入并非指从键盘敲入,而是从字符串中
输入),其中s是题中的字符串。接下来,就将is当作cin用,就可以啦。当然,需要处理一下刚开始的字符串,将所有/替换为空格。且需要注意的是
,有一种特例是全为/,这种情况只需判断一下是否输出即可。
献上代码:
#include<iostream>
#include<string>
#include<sstream>
using namespace std; int main()
{
string s, temp;
while (cin >> s)
{
for (int i = 0; i < s.length(); i++)
if (s[i] == '/')
s.replace(i, 1, 1, ' ');//将斜杠代换为空格
istringstream is(s);//创建输入流
bool flag = 0;//判断是否有输入
while (is >> temp)
{
cout << '/' << temp;
flag = 1;
}
if (!flag)
cout << '/';
cout << endl;
}
return 0;
}

CDOJ_327 BerOS file system的更多相关文章

  1. Code Forces 20A BerOS file system

    A. BerOS file system time limit per test 2 seconds memory limit per test 64 megabytes input standard ...

  2. BerOS file system

    The new operating system BerOS has a nice feature. It is possible to use any number of characters '/ ...

  3. 题解 CF20A 【BerOS file system】

    对于此题,我的心近乎崩溃 这道题,注意点没有什么,相信大佬们是可以自己写出来的 我是蒟蒻,那我是怎么写出来的啊 好了,废话少说,开始进入正题 这道题,首先我想到的是字符串的 erase 函数,一边运行 ...

  4. BerOS File Suggestion(字符串匹配map)

    BerOS File Suggestion(stl-map应用) Polycarp is working on a new operating system called BerOS. He asks ...

  5. Design and Implementation of the Sun Network File System

    Introduction The network file system(NFS) is a client/service application that provides shared file ...

  6. 乌版图 read-only file system

    今天在启动虚拟机的时候,运行命令svn up的时候,提示lock,并且read-only file system,这个....我是小白啊,怎么办?前辈在专心写代码,不好打扰,果断找度娘啊 于是乎,折腾 ...

  7. File system needs to be upgraded. You have version null and I want version 7

    安装hbase时候报错: File system needs to be upgraded. You have version null and I want version 7 注: 我安装的hba ...

  8. Linux系统启动错误 contains a file system with errors, check forced解决方法

    /dev/sda1 contains a file system with errors, check forced./dev/sda1: Inodes that were part of a cor ...

  9. Linux 执行partprobe命令时遇到Unable to open /dev/sr0 read-write (Read-only file system)

    在使用fdisk创建分区时,我们会使用partprobe命令可以使kernel重新读取分区信息,从而避免重启系统,但是有时候会遇到下面错误信息"Warning: Unable to open ...

随机推荐

  1. python网络-Socket之TCP编程(26)

    一.TCP简介 1.TCP介绍 TCP协议,传输控制协议(英语:Transmission Control Protocol,缩写为 TCP)是一种面向连接的.可靠的.基于字节流的传输层通信协议. TC ...

  2. python中字符串的一些用法

    一.字符串的拼接:      a=‘123’      b=‘abc’       d=‘hello world’ 1.print(a+b) 2.print(a,b) 3. c=‘ ’.join((a ...

  3. 汇编语言 Part 1——简介、基本语法、内存分段与内存地址

    简介 什么是汇编语言? 汇编语言是一种低级的编程语言,在程序的语句和体系结构的机器代码指令之间有很强的对应关系. 每种汇编语言都特定于特定的计算机体系结构,但需要解释或编译.汇编语言也可以称为符号机器 ...

  4. poj-3009 curling2.0(搜索)

    Curling 2.0 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26408   Accepted: 10546 Des ...

  5. HBase0.94.2-cdh4.2.0需求评估测试报告1.0之五

    根据以上图分析得出以下结论: 1. 在上面的hbase配置下,顺序和随机写记录(每条记录1K),每写入86-87M(大小可配)左右数据生成一个磁盘文件(store file). 2. 在上面的hbas ...

  6. 为工程添加上下文菜单(ContextMenu)

    上下文菜单大多数情况下都是为ListView中的Item添加的,长按2S左右跳出菜单,添加上下文菜单必须重写活动中的onCreateContextMenu()方法和onContextItemSelec ...

  7. MySQL 的MAC终端一些指令总结

    开启MySQL服务 sudo /usr/local/mysql/support-files/mysql.server start 关闭MySQL服务 udo /usr/local/mysql/supp ...

  8. 3224: Tyvj 1728 普通平衡树(新板子)

    3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 17048  Solved: 7429[Submit][St ...

  9. Java做爬虫也很方便

    首先我们封装一个Http请求的工具类,用HttpURLConnection实现,也可以用HttpClient, 或者直接用Jsoup来请求. 工具类实现比较简单,就一个get方法,读取请求地址的响应内 ...

  10. Hydux: 一个 Elm-like 的 全功能的 Redux 替代品

    在学习和使用 Fable + Elmish 一段时间之后,对 Elm 架构有了更具体的了解, 和预料中的一样,Redux 这种来自 Elm 的风格果然还是和强类型的 Meta Language 语言更 ...