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 ...
随机推荐
- MySQL练习50题
介绍一个学习SQL的网站:https://sqlbolt.com/ 习题来源于网络,SQL语句是自己的练习答案,部分参考了网络上的答案. 花了一晚上的时间做完,个人认为其中的难点有:分组提取前几名的数 ...
- hdu 4565
Problem Description A sequence Sn is defined as:Where a, b, n, m are positive integers.┌x┐is the cei ...
- Python学习-day8 socket进阶
还是继续socket网络编程的学习. socket.socket(family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None) Socket Fami ...
- SDOJ 3740 Graph
8.9 t3 [描述] 给你一个图,一共有 N 个点,2*N-2 条有向边. 边目录按两部分给出 1. 开始的 n-1 条边描述了一颗以 1 号点为根的生成树,即每个点都可以由 1 号点 到达. 2. ...
- django model的设计
1 设计blog的显示界面: 在blog/admin.py修改 from django.contrib import admin from blog.models import BlogPost # ...
- Clarke and five-pointed star
Clarke is a patient with multiple personality disorder. One day, Clarke turned into a learner of geo ...
- 【java基础 16】抽象类和接口的区别
导读:前两天闲着没事儿,看了本书,然后写了点代码,在接口里面写了默认方法实现,因为书上说这个特性是从java8开始的,我还特地给测了一下java7. 没过几天,就有一个技术分享会,刚好也是讲java8 ...
- sgen.exe 未能运行
指定的任务可执行文件“sgen.exe”未能运行.文件名或扩展名太长. 解决方式,右键项目属性->生成 把下图红框的“开”设置成“自动”
- 九度oj 题目1007:奥运排序问题
九度oj 题目1007:奥运排序问题 恢复 题目描述: 按要求,给国家进行排名. 输入: 有多组数据. 第一行给出国家数N,要求排名的国家数M,国家号 ...
- Golang遇到的问题记录
1,windows cmd 结束输入问题 func main() { counts := make(map[string]int) countLines(os.Stdin, counts) fmt.P ...