diff options
Diffstat (limited to '10009/roads.cpp')
| -rw-r--r-- | 10009/roads.cpp | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/10009/roads.cpp b/10009/roads.cpp index 9198847..4ce43b8 100644 --- a/10009/roads.cpp +++ b/10009/roads.cpp @@ -6,6 +6,8 @@ using namespace std; bool print_path(int [][26], int start, int dest, string &path, bool visited[]); +string reverse(string in); + int main(){ int tc; cin>>tc; @@ -13,7 +15,7 @@ int main(){ int r, q, c1, c2; char city1[100], city2[100]; - int map[26][26] = {0}; + int map[26][26] = {0}; cin>>r>>q; while(r--){ cin>>city1>>city2; @@ -22,20 +24,35 @@ int main(){ map[c1][c2] = 1; map[c2][c1] = 1; - } - + } + while(q--){ - string path=""; int i=0;bool viz[26]; + string path=""; + bool viz[26]={false}; cin>>city1>>city2; c1 = (int)city1[0] % 65; c2 = (int)city2[0] % 65; print_path(map, c1, c2, path, viz); - cout<<path<<endl; + cout<<reverse(path)<<endl; } + if(tc>0) + cout<<endl; } } +/* + +FIND(dest, node) + if node == dest: + path+=node + return true + else + for node in unvisited(node.pi) + visited[node]=true + if(FIND(dest, node)) + path+=node +*/ bool print_path(int map[26][26], int start, int dest, string &path, bool visited[]){ if(start==dest){ path+=char(start+65); @@ -56,15 +73,10 @@ bool print_path(int map[26][26], int start, int dest, string &path, bool visited } } -/* - -FIND(dest, node) - if node == dest: - path+=node - return true - else - for node in unvisited(node.pi) - visited[node]=true - if(FIND(dest, node)) - path+=node -*/ +string reverse(string in){ + int j=in.length(); + string rev; + while(j--) + rev+=in[j]; + return rev; +} |
