CDOJ_327 BerOS file system
原题地址: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下的最简格式,即目录间由一个斜杠隔开,根目录前有一个斜杠。说白了就是将多个斜杠变为一个。
<sstream>
,这是处理字符串流的库。然后创建一个输入流isstream
is(s)
(注意,这里的输入并非指从键盘敲入,而是从字符串中/
替换为空格。且需要注意的是/
,这种情况只需判断一下是否输出即可。献上代码:
#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的更多相关文章
- Code Forces 20A BerOS file system
A. BerOS file system time limit per test 2 seconds memory limit per test 64 megabytes input standard ...
- BerOS file system
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/ ...
- 题解 CF20A 【BerOS file system】
对于此题,我的心近乎崩溃 这道题,注意点没有什么,相信大佬们是可以自己写出来的 我是蒟蒻,那我是怎么写出来的啊 好了,废话少说,开始进入正题 这道题,首先我想到的是字符串的 erase 函数,一边运行 ...
- BerOS File Suggestion(字符串匹配map)
BerOS File Suggestion(stl-map应用) Polycarp is working on a new operating system called BerOS. He asks ...
- Design and Implementation of the Sun Network File System
Introduction The network file system(NFS) is a client/service application that provides shared file ...
- 乌版图 read-only file system
今天在启动虚拟机的时候,运行命令svn up的时候,提示lock,并且read-only file system,这个....我是小白啊,怎么办?前辈在专心写代码,不好打扰,果断找度娘啊 于是乎,折腾 ...
- 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 ...
- 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 ...
- Linux 执行partprobe命令时遇到Unable to open /dev/sr0 read-write (Read-only file system)
在使用fdisk创建分区时,我们会使用partprobe命令可以使kernel重新读取分区信息,从而避免重启系统,但是有时候会遇到下面错误信息"Warning: Unable to open ...
随机推荐
- PyCharm2019 激活方式
1.修改hosts激活:需要修改hosts,稳定无影响,持续更新,推荐~ 一.修改hosts激活 1.修改hosts文件 将0.0.0.0 account.jetbrains.com和0.0.0.0 ...
- static关键字所导致的内存泄漏问题
大家都知道内存泄漏和内存溢出是不一样的,内存泄漏所导致的越来越多的内存得不到回收的失手,最终就有可能导致内存溢出,下面说一下使用staitc属性所导致的内存泄漏的问题. 在dalvik虚拟机中,sta ...
- sql执行过长,如何入手优化
一条sql执行过长的时间,你如何优化,从哪些方面 1.查看sql是否涉及多表的联表或者子查询,如果有,看是否能进行业务拆分,相关字段冗余或者合并成临时表(业务和算法的优化)2.涉及链表的查询,是否能进 ...
- 线段树:CDOJ1591-An easy problem A (RMQ算法和最简单的线段树模板)
An easy problem A Time Limit: 1000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Pr ...
- Linux学习-编译前的任务:认识核心与取得核心原始码
什么是核心 (Kernel) Kernel 其实核心就是系统上面的一个文件而已, 这个文件包含了驱动主机各项硬 件的侦测程序与驱动模块. 核心文件通常被放置成 /boot/vmlinuz-xxx ,不 ...
- LAMP动态网站安装脚本
#!/bin/bash #auto make install LAMP #by authors zhangjianghua #httpd define path variable H_FILES=ht ...
- JS实现——Base64编码解码,带16进制显示
在网上找了个JS实现的Base64编码转换,所以就想自己研究下,界面如下: 将代码以BASE64方式加密.解密 请输入要进行编码或解码的字符: 编码结果以ASCII码16进制显示 解码结果以ASCII ...
- Django Form one
前戏: FromData:三种方式获取FromData 1. 创建一个FromData 的对象,然后再用append 的方法追个添加键值对 var formdata = new FormData(); ...
- 淘宝的TProfile分析
TProfile是一个用来抓取性能数据的工具.大概是去年的时候对其分析了一下,并将它改造成了用于分析学习开源产品时的一个trace工具(不是很完善,自己用够用).现在将之前的笔记翻出来,记录一下. 1 ...
- python算法-汉诺塔问题
汉诺塔问题 初始状态: 思考:当盘子的个数是3的时候,大家写出移动顺序 移动的步骤: 3个盘子,从a到c 1.前面两个盘子,从a到b 1)把前面一个盘子,从a到c a->c 2)把第二个盘子 ...