summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAditya Naik2018-05-12 23:11:09 -0400
committerAditya Naik2018-05-12 23:11:09 -0400
commit10f6ccbb4c699048e54db3c4b9ca9fce0c1dc950 (patch)
tree2c43fd4391a773a2853e90a318a787a0464d8368
parentc389d40b79b8de8b2b2631793492ea55d9740b87 (diff)
f#ing finally
-rw-r--r--10009/roads.cpp46
-rw-r--r--10009/roads.in39
2 files changed, 66 insertions, 19 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;
+}
diff --git a/10009/roads.in b/10009/roads.in
index b15368d..d48ad5b 100644
--- a/10009/roads.in
+++ b/10009/roads.in
@@ -1,4 +1,5 @@
-1
+4
+
7 3
Rome Turin
Turin Venice
@@ -9,4 +10,38 @@ Venice Athens
Turin Milan
Turin Pisa
Milan Florence
-Athens Genoa \ No newline at end of file
+Athens Genoa
+
+7 3
+Rome Turin
+Turin Venice
+Turin Genoa
+Rome Pisa
+Pisa Florence
+Venice Athens
+Turin Milan
+Turin Pisa
+Milan Florence
+Athens Genoa
+
+8 3
+Rome Chittagong
+Rome Khulna
+Rome Pabna
+Rome Sylhet
+Sylhet Moulovibazar
+Chittagong Bandorban
+Pabna Gaibandha
+Rome Zurich
+Rome Chittagong
+Khulna Gaibandha
+Pabna Sylhet
+
+6 1
+Rome BUET
+BUET TSC
+TSC Shahbag
+Shahbag Nilkhet
+Nilkhet Katabon
+Katabon ElephantRoad
+ElephantRoad Rome