• ccf-路径解析201604-3


    C++没有split函数

    但是有一个简单的方法,利用stringstream构建;

    然后这道题就很简单啦 还要注意不能用cin 因为有空行的存在

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 vector <string> f_cur,f_now;
     4 int n;
     5 vector <string> split (string str,const char flag='/') {
     6     istringstream iss(str);
     7     vector <string> ans;
     8     while (getline(iss,str,flag)) {
     9         if (str.size()) 
    10             ans.push_back(str);
    11     }
    12     return ans;
    13 }
    14 void _formal (vector <string>& ans, vector <string> f_now) {
    15     for (int i=0;i<f_now.size();i++) {
    16         if (f_now[i]==".") continue;
    17         else if (f_now[i]==".."){
    18             if (ans.size())
    19                 ans.pop_back();
    20         }
    21         else    ans.push_back(f_now[i]);
    22     }
    23 } 
    24 int main ()
    25 {   
    26     string str;
    27     cin>>n>>str; getchar();
    28     f_cur=split(str);
    29     while (n--) {
    30         getline(cin,str);  f_now=split(str);  // 开始用cin 导致只有90
    31         vector <string> ans;
    32         if (str.size()&&str[0]=='/')  _formal (ans,f_now);
    33         else {
    34             ans=f_cur;
    35             _formal (ans,f_now);
    36         }
    37         if (ans.size()) {
    38             for (int i=0;i<ans.size();i++)
    39                 cout<<"/"<<ans[i];
    40             cout<<"
    ";
    41         }
    42         else cout<<"/
    ";
    43     }
    44     return 0;
    45 } 
    抓住青春的尾巴。。。
  • 相关阅读:
    pptpvpn链接问题
    nginx网站架构优化思路(原)
    KEEPALIVED 检测RS原理
    linux 做gw(nat)详细配置
    pptpvpn 连接后 无法上外网
    网站最常见的错误
    Python服务器开发 -- 网络基础
    python高性能编程方法一
    一步步来用C语言来写python扩展
    http响应Last-Modified和ETag
  • 原文地址:https://www.cnblogs.com/xidian-mao/p/10495175.html
Copyright © 2020-2023  润新知