码迷,mamicode.com
首页 > 其他好文 > 详细

stl+模拟 CCF2016 4 路径解析

时间:2016-09-08 14:29:46      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:

 1 // stl+模拟 CCF2016 4 路径解析
 2 // 一开始题意理解错了。。。。
 3 
 4 #include <iostream>
 5 #include <string>
 6 #include <vector>
 7 using namespace std;
 8 void fre() {freopen("in.txt","r",stdin);}
 9 vector<string> l;
10 int main(){
11     int n;
12     string str;
13     cin>>n>>str;
14     getchar();
15     for(int i=1;i<=n;i++){
16         string s;
17         getline(cin,s);
18         if(s[0]!=/) s=str+/+s;
19         if(s.size()==0) s=str;
20         int pos;
21         while((pos=s.find("//"))!=-1){
22             int count=2;
23             while(s[pos+count]==/) count++;
24             s.erase(pos,count-1);
25         }
26         while((pos=s.find("/../"))!=-1){
27             if(pos==0){
28                 s.erase(pos+1,3);
29             }
30             else{
31                 int p=s.rfind(/,pos-1);
32                 s.erase(p,pos-p+3);
33             }
34         }
35 
36         while((pos=s.find("/./"))!=-1){
37             s.erase(pos,2);
38         }
39 
40         if(s.size()>1&&s[s.size()-1]==/)
41             s.erase(s.size()-1);
42         l.push_back(s);
43     }
44     for(int i=0;i<n;i++){
45         cout<<l[i]<<endl;
46     }
47     return 0;
48 }

 

stl+模拟 CCF2016 4 路径解析

标签:

原文地址:http://www.cnblogs.com/ITUPC/p/5852728.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!