A. BerOS file system

来源:互联网 发布:mac 梦幻西游手游网页 编辑:程序博客网 时间:2024/06/05 11:17
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.

Sample test(s)
input
//usr///local//nginx/sbin
output
/usr/local/nginx/sbin


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<iomanip>
#include<list>
#include<deque>
#include<map>
#include <stdio.h>
#include <queue>
#include <stack>
#define maxn 10000+5
#define ull unsigned long long
#define ll long long
#define reP(i,n) for(i=1;i<=n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define cle(a) memset(a,0,sizeof(a))
#define mod 90001
#define PI 3.141592657
#define INF 1<<30
const ull inf = 1LL << 61;
const double eps=1e-5;

using namespace std;

bool cmp(int a,int b){
return a>b;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
string s;
while(cin>>s){
stack
<char>st;
for(int i=0;i<s.size();i++){
if(st.empty())
st
.push(s[i]);
else
if(st.top()=='/'&&s[i]=='/'){
continue;
}
else st.push(s[i]);
}
string t="";
while(!st.empty()){
t
+=st.top();
st
.pop();
}
if(t.size()>1){
for(int i=t.size()-1;i>=1;i--)
cout
<<t[i];
if(t[0]!='/')cout<<t[0];
}
else cout<<t[0];
cout
<<endl;
}
return0;
}


0 0
原创粉丝点击