#!/usr/bin/env bash
if graph="$(mktemp -d)" || { echo failed; exit 2; } then
trap 'rm -rf "${graph}"' exit
fi
while read start end; do
mkdir -p "${graph}/${end}/${start}" "${graph}/${start}"
done
while [[ $(ls -1 "${graph}" | wc -l) -gt 0 ]]; do
for u in ${graph}/*; do
[[ $(ls -1 "${u}" | wc -l) -eq 0 ]] && { echo "$(basename ${u})"; break; }
done | {
read pop || { echo cylic; exit 1; }
echo "${pop}"
rmdir "${graph}/${pop}"
for v in ${graph}/*; do
[[ -d "${v}/${pop}" ]] && rmdir "${v}/${pop}"
done
}
done
大家看看写得对吗?
附赠输入输出:
CSCI-E-50a CSCI-E-50b
CSCI-E-50b CSCI-E-160
CSCI-E-160 CSCI-E-162
CSCI-E-50b CSCI-E-119
CSCI-E-119 CSCI-E-215
CSCI-E-119 CSCI-E-124
CSCI-E-50b MATH-E-104
MATH-E-10 CSCI-E-119
MATH-E-10 MATH-E-104
MATH-E-104 CSCI-E-124
CSCI-E-50a
CSCI-E-50b
CSCI-E-160
CSCI-E-162
MATH-E-10
CSCI-E-119
CSCI-E-215
MATH-E-104
CSCI-E-124
玩得开心~
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.