A. BerOS file system
2016-04-21 19:02
387 查看
A. BerOS file systemtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputThe 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.InputThe 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.OutputThe path in normalized form.Sample test(s)input
//usr///local//nginx/sbinoutput
/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; } return 0; }
相关文章推荐
- A. World Football Cup
- A. Triangle
- A. Noldbach problem
- A. Flag
- A. Cottage Village
- A. Letter
- A. Numbers
- A. Super Agent
- A. Increasing Sequence
- A. Power Consumption Calculation
- 【问题解决】FragmentTabHost 底部菜单栏,切换Frgment时重新加载问题
- 使用Ajax实现异步用户名验证
- hiho#1139 : 二分·二分答案
- A. Die Roll
- 错排公式
- Crontab配置及使用总结
- Oracle内置表二
- CalendarView功能与用法(日历视图)
- 报名|「OneAPM x DaoCloud」技术公开课:Docker性能监控!
- Friday the Thirteenth