fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. string printOrder(vector <string> v)
  6. {
  7.  
  8. // create graph
  9. unordered_map <char, vector<char> > graph;
  10.  
  11. // set of chars
  12. unordered_set <char> nodes;
  13. for(string s : v)
  14. {
  15. char prev = s[0];
  16. nodes.insert(s[0]);
  17. for(int i = 1; i < s.length(); i++)
  18. {
  19. graph[prev].push_back(s[i])
  20. prev = s[i];
  21. nodes.insert(s[i]);
  22. }
  23. }
  24.  
  25.  
  26. unordered_set <char> vis;
  27.  
  28. // 1 a 0 t
  29. // 5 a 2 0 t
  30.  
  31.  
  32.  
  33. // p 0
  34.  
  35. // z q p a
  36.  
  37. // 1 -> a
  38. //
  39.  
  40. string ans = "";
  41. for(char c : nodes)
  42. {
  43. string dfsResult = "";
  44. if (vis.find(c) == vis.end())
  45. {
  46. dfsResult = dfs(c, graph, vis);
  47. }
  48.  
  49. ans = dfsResult + ans;
  50. }
  51.  
  52. }
  53.  
  54.  
  55. int main() {
  56. // your code goes here
  57. return 0;
  58. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘std::__cxx11::string printOrder(std::vector<std::__cxx11::basic_string<char> >)’:
prog.cpp:9:2: error: ‘unordered_map’ was not declared in this scope
  unordered_map <char, vector<char> > graph;
  ^~~~~~~~~~~~~
prog.cpp:9:2: note: ‘std::unordered_map’ is defined in header ‘<unordered_map>’; did you forget to ‘#include <unordered_map>’?
prog.cpp:3:1:
+#include <unordered_map>
 using namespace std;
prog.cpp:9:2:
  unordered_map <char, vector<char> > graph;
  ^~~~~~~~~~~~~
prog.cpp:9:17: error: expected primary-expression before ‘char’
  unordered_map <char, vector<char> > graph;
                 ^~~~
prog.cpp:12:2: error: ‘unordered_set’ was not declared in this scope
  unordered_set <char> nodes;
  ^~~~~~~~~~~~~
prog.cpp:12:2: note: ‘std::unordered_set’ is defined in header ‘<unordered_set>’; did you forget to ‘#include <unordered_set>’?
prog.cpp:3:1:
+#include <unordered_set>
 using namespace std;
prog.cpp:12:2:
  unordered_set <char> nodes;
  ^~~~~~~~~~~~~
prog.cpp:12:17: error: expected primary-expression before ‘char’
  unordered_set <char> nodes;
                 ^~~~
prog.cpp:16:3: error: ‘nodes’ was not declared in this scope
   nodes.insert(s[0]);
   ^~~~~
prog.cpp:19:4: error: ‘graph’ was not declared in this scope
    graph[prev].push_back(s[i])
    ^~~~~
prog.cpp:19:4: note: suggested alternative: ‘isgraph’
    graph[prev].push_back(s[i])
    ^~~~~
    isgraph
prog.cpp:26:17: error: expected primary-expression before ‘char’
  unordered_set <char> vis;
                 ^~~~
prog.cpp:41:15: error: ‘nodes’ was not declared in this scope
  for(char c : nodes)
               ^~~~~
prog.cpp:44:7: error: ‘vis’ was not declared in this scope
   if (vis.find(c) == vis.end())
       ^~~
prog.cpp:46:23: error: ‘graph’ was not declared in this scope
    dfsResult = dfs(c, graph, vis);
                       ^~~~~
prog.cpp:46:23: note: suggested alternative: ‘isgraph’
    dfsResult = dfs(c, graph, vis);
                       ^~~~~
                       isgraph
prog.cpp:46:16: error: ‘dfs’ was not declared in this scope
    dfsResult = dfs(c, graph, vis);
                ^~~
prog.cpp:52:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
stdout
Standard output is empty