PROBLEM LINK:
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;
}