前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Code Forces 20A BerOS file system

Code Forces 20A BerOS file system

作者头像
ShenduCC
发布2018-04-26 16:14:56
6200
发布2018-04-26 16:14:56
举报
文章被收录于专栏:算法修养算法修养

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 <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;
char a[105];
char b[105];
int main()
{
    gets(a);
    bool tag=0;
    int len=strlen(a);
    int cnt=0;
    for(int i=0;i<len;i++)
    {
        if(a[i]!='/')
        {
           // cout<<a[i];
            b[cnt++]=a[i];
            tag=0;
        }

        else
        {
            if(!tag)
            {
                //cout<<a[i];
                b[cnt++]=a[i];
                tag=1;
            }
        }
    }
    if(b[0]!='/')
        cout<<'/';
    for(int i=0;i<cnt;i++)
    {
        if(i==cnt-1&&b[i]=='/'&&cnt!=1)
            continue;
       cout<<b[i];
    }
    cout<<endl;
    return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-04-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档