原题地址: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. 等待唤醒(wait / notify)机制

    如果一个线程从头到尾执行完也不和别的线程打交道的话,那就不会有各种安全性问题了.但是协作越来越成为社会发展的大势,一个大任务拆成若干个小任务之后,各个小任务之间可能也需要相互协作最终才能执行完整个大任 ...

  2. BugBash活动分享

    此文已由作者夏君授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. BugBash源至微软概念,翻译为<缺陷大扫除>,顾名思义是集中大家力量全面清扫Bug,确保产品质 ...

  3. 如何利用App打造自明星实现自盈利

    1.了解各个概念      为了大家都能看懂这篇文章,先说明几个概念.       App(Application):可以在移动设备上使用,满足人们咨询.购物.社交.娱乐.搜索等需求的一切应用程序.  ...

  4. python-安装及配置环境变量

    1.python安装十分简单,直接下载与自己电脑位数匹配的python安装包进行安装即可. 这里提供python27的安装包供大家参考. win-32位: 链接: https://pan.baidu. ...

  5. Jmeter Cluster

    Jmeter 是开源软件,100%纯java应用程序,专门为负载测试和性能测试. Jmeter的特性包括: 1.负载测试和性能测试许多不同的服务器/协议类型: Web - HTTP, HTTPS SO ...

  6. 【bzoj3744】Gty的妹子序列 分块+树状数组+主席树

    题目描述 我早已习惯你不在身边, 人间四月天 寂寞断了弦. 回望身后蓝天, 跟再见说再见…… 某天,蒟蒻Autumn发现了从 Gty的妹子树(bzoj3720) 上掉落下来了许多妹子,他发现 她们排成 ...

  7. 【Luogu】P1486郁闷的出纳员(Splay)

    题目链接 名副其实的调了一下午…… 每做一道题都是对我那不规范的Splay代码的刀刻斧凿一般的修正啊…… Splay.如果有一批员工不干了,那就找还能干的薪水最少的员工,把它splay到根,删除它的左 ...

  8. HDU——2723Electronic Document Security(STL map嵌套set做法)

    Electronic Document Security Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  9. spring分布式事务控制

    应用场景问题描述解决方法多数据源配置单元测试第一种方法:最大努力一次提交模式第二种方法:最大努力一次提交模式 但使用ChainedTransactionManagerChainedTransactio ...

  10. BZOJ 4551 [Tjoi2016&Heoi2016]树 ——并查集

    树剖显然可以做. 然而有一种更神奇的方法,并查集+时光倒流. 每个节点指向它上面最近的标记节点,标记节点指向自己,然后删除标记,就可以用并查集查询了. #include <map> #in ...