Skip to content

Commit b8cf06f

Browse files
author
computer0101
committed
add new line character after each user input scan to resolve scan issues in windows terminal
1 parent 409e2e9 commit b8cf06f

File tree

104 files changed

+319
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+319
-319
lines changed

algorithms/01knapsack_dp/01knapsack_dp.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ func main() {
6666
var temp int
6767
fmt.Println("\n-- 0-1 Knapsack Problem using Dynamic Programming --")
6868
fmt.Print("\nEnter the number of objects: ")
69-
fmt.Scanf("%d", &size)
69+
fmt.Scanf("%d\n", &size)
7070
fmt.Println("Start entering weight and value of each object:")
7171
for i := 0; i < size; i++ {
7272
fmt.Print("\nWeight: ")
73-
fmt.Scanf("%d", &temp)
73+
fmt.Scanf("%d\n", &temp)
7474
weights = append(weights, temp)
7575
fmt.Print("Value: ")
76-
fmt.Scanf("%d", &temp)
76+
fmt.Scanf("%d\n", &temp)
7777
values = append(values, temp)
7878
}
7979
fmt.Print("\nEnter the capacity of knapsack: ")
80-
fmt.Scanf("%d", &capacity)
80+
fmt.Scanf("%d\n", &capacity)
8181
knapsack()
8282
}
8383

algorithms/a_star/8_puzzle/8_puzzle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func main() {
5252
for j := range inputPuzzle[i] {
5353
value := -1
5454
fmt.Print("Enter for ", i+1, j+1, ": ")
55-
fmt.Scanf("%d", &value)
55+
fmt.Scanf("%d\n", &value)
5656
inputPuzzle[i][j] = value
5757
}
5858
fmt.Println("")

algorithms/a_star/directed_graph/graph.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func main() {
104104
fmt.Println("7. EXIT")
105105
var choice int
106106
fmt.Print("Enter your choice: ")
107-
fmt.Scanf("%d", &choice)
107+
fmt.Scanf("%d\n", &choice)
108108
switch choice {
109109
case 1:
110110
g.addVertex()
@@ -130,46 +130,46 @@ func (g graph) addVertex() {
130130
var vtxName string
131131
var vtxWeight int
132132
fmt.Print("Enter the name of vertex: ")
133-
fmt.Scanf("%s", &vtxName)
133+
fmt.Scanf("%s\n", &vtxName)
134134
fmt.Print("Enter the weight of vertex: ")
135-
fmt.Scanf("%d", &vtxWeight)
135+
fmt.Scanf("%d\n", &vtxWeight)
136136
g.addVertexToGraph(vtxName, vtxWeight)
137137
}
138138

139139
func (g graph) addEdge() {
140140
var fromVtx, toVtx string
141141
var edgeValue int
142142
fmt.Print("Enter the initial vertex name: ")
143-
fmt.Scanf("%s", &fromVtx)
143+
fmt.Scanf("%s\n", &fromVtx)
144144
fmt.Print("Enter the destination vertex name: ")
145-
fmt.Scanf("%s", &toVtx)
145+
fmt.Scanf("%s\n", &toVtx)
146146
fmt.Print("Enter the weight of edge: ")
147-
fmt.Scanf("%d", &edgeValue)
147+
fmt.Scanf("%d\n", &edgeValue)
148148
g.addEdgeToGraph(fromVtx, toVtx, edgeValue)
149149
}
150150

151151
func (g graph) removeVertex() {
152152
var vtxName string
153153
fmt.Print("Enter the name of vertex: ")
154-
fmt.Scanf("%s", &vtxName)
154+
fmt.Scanf("%s\n", &vtxName)
155155
g.removeVertexFromGraph(vtxName)
156156
}
157157

158158
func (g graph) removeEdge() {
159159
var fromVtx, toVtx string
160160
fmt.Print("Enter the initial vertex name: ")
161-
fmt.Scanf("%s", &fromVtx)
161+
fmt.Scanf("%s\n", &fromVtx)
162162
fmt.Print("Enter the destination vertex name: ")
163-
fmt.Scanf("%s", &toVtx)
163+
fmt.Scanf("%s\n", &toVtx)
164164
g.removeEdgeFromGraph(fromVtx, toVtx)
165165
}
166166

167167
func (g graph) initAStarAlgo() {
168168
var initialVtx, goalVtx string
169169
fmt.Print("Enter the initial vertex name: ")
170-
fmt.Scanf("%s", &initialVtx)
170+
fmt.Scanf("%s\n", &initialVtx)
171171
fmt.Print("Enter the goal vertex name: ")
172-
fmt.Scanf("%s", &goalVtx)
172+
fmt.Scanf("%s\n", &goalVtx)
173173
if g[initialVtx] == nil {
174174
fmt.Println("Initial vertex does not exist.")
175175
return

algorithms/a_star/undirected_graph/graph.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func main() {
105105
fmt.Println("7. EXIT")
106106
var choice int
107107
fmt.Print("Enter your choice: ")
108-
fmt.Scanf("%d", &choice)
108+
fmt.Scanf("%d\n", &choice)
109109
switch choice {
110110
case 1:
111111
g.addVertex()
@@ -131,46 +131,46 @@ func (g graph) addVertex() {
131131
var vtxName string
132132
var vtxWeight int
133133
fmt.Print("Enter the name of vertex: ")
134-
fmt.Scanf("%s", &vtxName)
134+
fmt.Scanf("%s\n", &vtxName)
135135
fmt.Print("Enter the weight of vertex: ")
136-
fmt.Scanf("%d", &vtxWeight)
136+
fmt.Scanf("%d\n", &vtxWeight)
137137
g.addVertexToGraph(vtxName, vtxWeight)
138138
}
139139

140140
func (g graph) addEdge() {
141141
var fromVtx, toVtx string
142142
var edgeValue int
143143
fmt.Print("Enter the initial vertex name: ")
144-
fmt.Scanf("%s", &fromVtx)
144+
fmt.Scanf("%s\n", &fromVtx)
145145
fmt.Print("Enter the destination vertex name: ")
146-
fmt.Scanf("%s", &toVtx)
146+
fmt.Scanf("%s\n", &toVtx)
147147
fmt.Print("Enter the weight of edge: ")
148-
fmt.Scanf("%d", &edgeValue)
148+
fmt.Scanf("%d\n", &edgeValue)
149149
g.addEdgeToGraph(fromVtx, toVtx, edgeValue)
150150
}
151151

152152
func (g graph) removeVertex() {
153153
var vtxName string
154154
fmt.Print("Enter the name of vertex: ")
155-
fmt.Scanf("%s", &vtxName)
155+
fmt.Scanf("%s\n", &vtxName)
156156
g.removeVertexFromGraph(vtxName)
157157
}
158158

159159
func (g graph) removeEdge() {
160160
var fromVtx, toVtx string
161161
fmt.Print("Enter the initial vertex name: ")
162-
fmt.Scanf("%s", &fromVtx)
162+
fmt.Scanf("%s\n", &fromVtx)
163163
fmt.Print("Enter the destination vertex name: ")
164-
fmt.Scanf("%s", &toVtx)
164+
fmt.Scanf("%s\n", &toVtx)
165165
g.removeEdgeFromGraph(fromVtx, toVtx)
166166
}
167167

168168
func (g graph) initAStarAlgo() {
169169
var initialVtx, goalVtx string
170170
fmt.Print("Enter the initial vertex name: ")
171-
fmt.Scanf("%s", &initialVtx)
171+
fmt.Scanf("%s\n", &initialVtx)
172172
fmt.Print("Enter the goal vertex name: ")
173-
fmt.Scanf("%s", &goalVtx)
173+
fmt.Scanf("%s\n", &goalVtx)
174174
if g[initialVtx] == nil {
175175
fmt.Println("Initial vertex does not exist.")
176176
return

algorithms/activity_selection_gp/activity_selection_gp.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ func main() {
3333
fmt.Println("\n-- Activity Selection Problem using Greedy Approach --")
3434

3535
fmt.Print("\nEnter the number of activities: ")
36-
fmt.Scanf("%d", &n)
36+
fmt.Scanf("%d\n", &n)
3737
activities = make([]activity, n)
3838

3939
fmt.Println("Start entering starting and finishing times of each activities:")
4040
var temp float64
4141
for i := 0; i < n; i++ {
4242
fmt.Print("Start: ")
43-
fmt.Scanf("%f", &temp)
43+
fmt.Scanf("%f\n", &temp)
4444
activities[i].start = temp
4545
fmt.Print("Finish: ")
46-
fmt.Scanf("%f", &temp)
46+
fmt.Scanf("%f\n", &temp)
4747
activities[i].finish = temp
4848
}
4949

algorithms/assembly_line_scheduling/assembly_scheduling.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ func init() {
1919
func main() {
2020
fmt.Println("\n-- Assembly Line Scheduling --")
2121
fmt.Print("Enter the number of stations in assembly line: ")
22-
fmt.Scanf("%d", &stations)
22+
fmt.Scanf("%d\n", &stations)
2323

2424
fmt.Println("Start entering the costs:")
2525
var temp int
2626
for i := 0; i < 2; i++ {
2727
assembly[i] = make([]int, stations+2)
2828
for j := 0; j < stations+2; j++ {
2929
fmt.Print(i, "-", j, ": ")
30-
fmt.Scanf("%d", &temp)
30+
fmt.Scanf("%d\n", &temp)
3131
assembly[i][j] = temp
3232
}
3333
}
@@ -37,7 +37,7 @@ func main() {
3737
transport[i] = make([]int, stations+2)
3838
for j := 0; j < stations-1; j++ {
3939
fmt.Print(i+1, "-", j+1, ": ")
40-
fmt.Scanf("%d", &temp)
40+
fmt.Scanf("%d\n", &temp)
4141
transport[i][j+1] = temp
4242
}
4343
}

algorithms/binary_reflected_gray_codes/brgc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func main() {
99
fmt.Println("\n-- Binary Reflected Gray Codes --")
1010
var value int
1111
fmt.Print("\nEnter a value: ")
12-
fmt.Scanf("%d", &value)
12+
fmt.Scanf("%d\n", &value)
1313
if value < 1 {
1414
log.Fatal("Invalid value. Value must be greater than 0.")
1515
}

algorithms/combinations/with_r/combinations.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ func main() {
99
arr := make([]string, 0)
1010

1111
fmt.Print("\nEnter the value of n: ")
12-
fmt.Scanf("%d", &n)
12+
fmt.Scanf("%d\n", &n)
1313
fmt.Println("Start entering unique values of n:")
1414
for i := 0; i < n; i++ {
1515
var temp string
16-
fmt.Scanf("%s", &temp)
16+
fmt.Scanf("%s\n", &temp)
1717
arr = append(arr, temp)
1818
}
1919
fmt.Print("Enter the value of r: ")
20-
fmt.Scanf("%d", &r)
20+
fmt.Scanf("%d\n", &r)
2121

2222
data := make([]string, r)
2323

algorithms/combinations/without_r/combinations.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ func main() {
99
arr := make([]string, 0)
1010

1111
fmt.Print("\nEnter the value of n: ")
12-
fmt.Scanf("%d", &n)
12+
fmt.Scanf("%d\n", &n)
1313
fmt.Println("Start entering unique values of n:")
1414
for i := 0; i < n; i++ {
1515
var temp string
16-
fmt.Scanf("%s", &temp)
16+
fmt.Scanf("%s\n", &temp)
1717
arr = append(arr, temp)
1818
}
1919
fmt.Print("Enter the value of r: ")
20-
fmt.Scanf("%d", &r)
20+
fmt.Scanf("%d\n", &r)
2121

2222
data := make([]string, r)
2323

algorithms/convex_hull/ch_brute_force/ch_brute_force.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ func ConvexHull() []Point {
7676
}
7777

7878
// float64 to string
79-
xi := fmt.Sprintf("%f", arr[i].x)
80-
yi := fmt.Sprintf("%f", arr[i].y)
81-
xj := fmt.Sprintf("%f", arr[j].x)
82-
yj := fmt.Sprintf("%f", arr[j].y)
79+
xi := fmt.Sprintf("%f\n", arr[i].x)
80+
yi := fmt.Sprintf("%f\n", arr[i].y)
81+
xj := fmt.Sprintf("%f\n", arr[j].x)
82+
yj := fmt.Sprintf("%f\n", arr[j].y)
8383

8484
//string of x[i] y[i]
8585
strI := xi + yi

0 commit comments

Comments
 (0)