题解 | #路径打印#
路径打印
https://www.nowcoder.com/practice/64b472c9bed247b586859978d13145ad
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include<unordered_map>
using namespace std;
unordered_map<string, int> ma;
int main() {
while (1) {
ma.clear();
stringstream ss;
int n;
cin >> n;
if (n) {
string s;
int cnt = n;
vector<vector<string>> nums(n); int k = 0;
while (n--) {
cin >> s;
ss << s;
string t;
while (getline(ss, t, '\\')) {
nums[k].push_back(t);
}
k++; ss.clear(); ss.str("");
}
sort(nums.begin(), nums.end());
for (int i = 0; i < cnt; i++) {string cs;
for (int j = 0; j < nums[i].size(); j++) {
cs+=nums[i][j];
if (ma.count(cs)) continue;
for (int k = 0; k < 2*j; k++) {
cout << ' ';
}
cout << nums[i][j] << endl; ma[cs] = 1;
}
}
puts("");
}
else break;
}
}
// 64 位输出请用 printf("%lld")