Problem: Reverse a given string keeping its special character(s) at the same place
Input Format: First line contains a single integer, the number of testcases n. Next n line contains n strings as input.
(NOTE: The actual problem didn’t have the number of testcases as input. But for your better convenience we have worked with testcases.)
Sample Input:
3
intell#ect
h@ello
a#b@c
Sample Output:
tcelle#tni
o@lleh
c#b@a
Explanation: Here in the first example the whole string is reversed keeping the special character ‘#’ fixed in its original position i.e. on position 7.
In the second case, whole string is reversed keeping the special character ‘@’ fixed in its original position i.e. on position 2.
In the last case, the whole string is reversed keeping the special characters ‘#’, ‘@’ fixed in its original position i.e. on position 2 and 4 respectively.
Solution: We strongly recommend you to try the problem first before moving to the solution.
# Solution of String Reversal Except Special Characters problem in Python
# www.codewindow.in
def solve(s):
import re
str_list=re.findall("[a-z,A-Z]",s)
str_list.reverse()
for i in range(len(s)):
if ((ord(s[i])>=32 and ord(s[i])<=47) or (ord(s[i])>=58 and ord(s[i])<=64) or (ord(s[i])>=94 and ord(s[i])<=96) or (ord(s[i])>=123 and ord(str[i])<=126)):
str_list.insert(i,s[i])
print(''.join(str_list))
# Driver Code
test_case=int(input()); # Take number of testcases
while(test_case):
str=input()
solve(str)
test_case-=1
Input:
3
intell#ect
h@ello
a#b@c
Output:
tcelle#tni
o@lleh
c#b@a
Follow Us
You Missed
- UKG Hiring for Software Engineer
- Unlocking Innovation and Diversity: Accenture HackDiva Empowers Women in Tech with Cutting-Edge Solutions – codewindow.in
- QA Engineer Opportunities at Siemens Company: Apply Now – codewindow.in
- Transform Your Career with S&P Global: Apply for the Software Development Engineer Role and Lead the Future of Financial Technology Innovation – codewindow.in
- Unlock Your Potential at Accenture as an Associate Software Engineer – Elevate Your Career with Innovation and Excellence – codewindow.in
- Accelerate Your Career: Join NVIDIA’s Elite Software Engineering Internship Program and Shape the Future of Technology – codewindow.in
- Software Engineer at ABB: Unlock Innovation and Shape the Future – codewindow.in
- IBM Associate Systems Engineer Job: Boost Your Career with a Leading Technology Giant – codewindow.in
- Start Your IT Career Journey with Amazon: IT Services Support Associate I Opportunity – codewindow.in
- Shape the Future of Web: Front-End Software Engineer Opportunity at Google Cloud – codewindow.in
- Exciting Opportunity: Java Spring Boot Senior Developer Role at Infosys – codewindow.in
- Unlock Your Potential at Nokia: Software Engineer Opportunities Await – codewindow.in
- Join Microsoft’s World-Class Team as a Software Engineer and Shape the Future of Technology – codewindow.in
- Virtusa is Seeking Talented React JS Developers to Drive Digital Excellence – codewindow.in
- Join IBM Dynamic Team as a Full Stack Developer and Shape the Future – codewindow.in
- EY Welcomes Aspiring AI/ML Interns to Unlock the Future of -codewindow.in
- Wipro is Hiring Test Engineers to Elevate Quality Assurance – codewindow.in
- Deloitte Is Hiring: Analysts and Senior Analysts Wanted to Drive Innovation – codewindow.in
- Exciting Software Development Opportunity At Oracle – codewindow.in
- PayPal Hiring Data Analyst 1 – codewindow.in
- SIEMENS HEALTHINEERS Hiring Data Scientist ( ML & AI) – codewindow.in
- Programming in C++ – codewindow.in
- Programming in C++ – codewindow.in
- Unstop Hiring Challenges Internships and Hackathons – codewindow.in
- Programming in Python – codewindow.in
- Programming in Python – codewindow.in
- Programming in C++ – codewindow.in
- Programming in C++ – codewindow.in
- Programming in C++ – codewindow.in
- Programming in C++ – codewindow.in
- Programming in C++ – codewindow.in
- Data Structure – comprehensive guide – codewindow.in