CPCEJC3 - Editorial

PROBLEM LINK:

Practice

Author: Manish Motwani
Tester: Lavesh Garg
Editorialist: Lavesh Garg

DIFFICULTY:

SIMPLE

PREREQUISITES:

Strings

PROBLEM:

The problem is that we are given a string and we have to reverse the given String.

QUICK EXPLANATION:

we have to reverse a string.

EXPLANATION:

we have to run a for loop in reverse starting from the last index (eg.,index
=arr.length-1) and goes to the starting index of the array(eg…,index=0).

SOLUTIONS:

Setter's Solution
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);

	ll t;
	cin >> t;
	while(t--){
		string s;
		cin >> ws;
		getline(cin,s);
		reverse(s.begin() , s.end());
		for(char &c:s){
			if(c>='A' and c<='Z') c=c+32;
		}
		cout << s << endl;
	}

return 0;
}
Tester's Solution
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);

	ll t;
	cin >> t;
	while(t--){
		string s;
		cin >> ws;
		getline(cin,s);
		reverse(s.begin() , s.end());
		for(char &c:s){
			if(c>='A' and c<='Z') c=c+32;
		}
		cout << s << endl;
	}

return 0;
}
Editorialist's Solution
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);

	ll t;
	cin >> t;
	while(t--){
		string s;
		cin >> ws;
		getline(cin,s);
		reverse(s.begin() , s.end());
		for(char &c:s){
			if(c>='A' and c<='Z') c=c+32;
		}
		cout << s << endl;
	}

return 0;
}

what’s wrong in my code
for _ in range(int(input())):
arr=list(map(str,input().split()))
if(len(arr)==1):
s=arr[0]
s=s[::-1]
print(s.lower())
else:
for i in range(len(arr)):
s=arr[i]
s=s[::-1]
arr[i]=s.lower()
arr.reverse()
print(*arr)