20ABerOS file system

来源:互联网 发布:audition cc 2018 mac 编辑:程序博客网 时间:2024/06/05 19:03

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

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

The first line of the input 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.

Examples
input
//usr///local//nginx/sbin
output
/usr/local/nginx/sbin

题意:输入一串字符,是一个电脑路径,把路径中有大于一个/的去掉只保留一个。末尾有/的去掉。

题意:模拟

#include<bits/stdc++.h>using namespace std;int main(){    char s[1000];    int m;    while(cin>>s)    {        m=0;        int len=strlen(s);        for(int i=1; i<len; i++)            if(s[i]!='/'||s[m]!='/')                s[++m]=s[i];        while(m>0&&s[m]=='/') ///末尾是'/'去掉            m--;        s[m+1]=0; ///字符串结尾添加'/0'        puts(s);    }    return 0;}


原创粉丝点击