fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <boost/algorithm/string.hpp>
  5. #include <cassert>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. std::vector<std::string> name;
  12. std::map<std::string, std::string> boss;
  13. std::map<std::string, int> ability;
  14.  
  15. for (std::string line; std::cin >> line; ) {
  16. std::vector<std::string> v;
  17. boost::split(v, line, boost::is_any_of(","));
  18. assert(boss.count(v[0]) == 0);
  19. name.push_back(v[0]);
  20. boss[v[0]] = v[1];
  21. ability[v[0]] = std::stoi(v[2]);
  22. }
  23.  
  24. for (const auto &x : name) {
  25. int total = ability[x];
  26. std::string series = x;
  27. for (std::string y = boss[x]; !y.empty(); y = boss[y]) {
  28. series += " -> " + y;
  29. total += ability[y];
  30. }
  31. std::cout << total << " : " << series << std::endl;
  32. }
  33. }
  34.  
Success #stdin #stdout 0.01s 5476KB
stdin
ガンド部長,ブリ事業部長,9000
モジャコ,ヤズ係長,39000
ワラサ部長,ブリ事業部長,46000
メジロ部長,ブリ事業部長,34000
ブリ事業部長,,32000
ツバイソ,コズクラ係長,24000
ツバス係長,ハマチ課長,23000
ワカナ,ツバス係長,4000
イナダ課長,ワラサ部長,5000
ヤズ係長,ハマチ課長,23000
ワカナゴ係長,イナダ課長,49000
フクラギ課長,ガンド部長,17000
ハマチ課長,メジロ部長,19000
コズクラ係長,フクラギ課長,31000
stdout
41000 : ガンド部長 -> ブリ事業部長
147000 : モジャコ -> ヤズ係長 -> ハマチ課長 -> メジロ部長 -> ブリ事業部長
78000 : ワラサ部長 -> ブリ事業部長
66000 : メジロ部長 -> ブリ事業部長
32000 : ブリ事業部長
113000 : ツバイソ -> コズクラ係長 -> フクラギ課長 -> ガンド部長 -> ブリ事業部長
108000 : ツバス係長 -> ハマチ課長 -> メジロ部長 -> ブリ事業部長
112000 : ワカナ -> ツバス係長 -> ハマチ課長 -> メジロ部長 -> ブリ事業部長
83000 : イナダ課長 -> ワラサ部長 -> ブリ事業部長
108000 : ヤズ係長 -> ハマチ課長 -> メジロ部長 -> ブリ事業部長
132000 : ワカナゴ係長 -> イナダ課長 -> ワラサ部長 -> ブリ事業部長
58000 : フクラギ課長 -> ガンド部長 -> ブリ事業部長
85000 : ハマチ課長 -> メジロ部長 -> ブリ事業部長
89000 : コズクラ係長 -> フクラギ課長 -> ガンド部長 -> ブリ事業部長