File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ Problem Link: https://practice.geeksforgeeks.org/problems/reverse-a-string-using-stack/1
3
+
4
+ An string of words is given, the task is to reverse the string using stack.
5
+
6
+ Input Format:
7
+ The first line of input will contains an integer T denoting the no of test cases.
8
+ Then T test cases follow. Each test case contains a string s of words without spaces.
9
+
10
+ Output Format:
11
+ For each test case ,print the reverse of the string in new line.
12
+
13
+ Your Task:
14
+ Since this is a function problem, you don't need to take any input. Just complete the provided function.
15
+
16
+ Constraints:
17
+ 1 <= T <= 100
18
+ 1 <= length of the string <= 100
19
+
20
+ Example:
21
+ Input:
22
+ 2
23
+ GeeksQuiz
24
+ GeeksforGeeks
25
+ Output:
26
+ ziuQskeeG
27
+ skeeGrofskeeG
28
+ """
29
+ {
30
+
31
+ if __name__ == '__main__' :
32
+ t = int (input ())
33
+ for i in range (t ):
34
+ str1 = input ()
35
+ print (reverse (str1 ))
36
+ }
37
+ ''' This is a function problem.You only need to complete the function given below '''
38
+
39
+ def reverse (string ):
40
+ stack = []
41
+ for c in string :
42
+ stack .append (c )
43
+ reversedString = []
44
+ while stack :
45
+ reversedString .append (stack .pop ())
46
+ return "" .join (reversedString )
47
+
You can’t perform that action at this time.
0 commit comments