文章

2

粉丝

140

获赞

1

访问

15.0k

头像
先排序,再逐行parse后输出,坑:缩进是两个whitespace
推荐阅读
P1279 上海交通大学机试题
发布于2021年7月4日 23:19
阅读数 7.9k

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

void whiteSpace(int deep){
    for(int i = 0; i < deep; i++){
        cout << "  ";
    }
}
void printDirect(string s, int whitePrefix){
    //完整地打印 s 的 dir tree
    int deep = -1;
    for(size_t i = 0; i < s.size(); i++){
        size_t j = i;
        while(s[j] != '\\' && j != s.size()) j++;
        string dir = s.substr(i, j - i);
        deep++;
        whiteSpace(deep + whitePrefix);
        cout << dir << endl;
        i = j;
    }
}
void printRelate(string a, string p){
    //基于上一行p的打印情况部分打印a
    int same = 0;
    size_t i = 0;
    for(i = 0; i < p.size() && i < a.size(); i++){
        if(a[i] == p[i]){
            if(a[i] == '\\') same++;
        } else {
            break;
        }
    }
    a = a.substr(i, a.size() - i); //前i个字符都无需打印,但是需要有same个whiteSpace作为前缀
    printDir...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发