-
Notifications
You must be signed in to change notification settings - Fork 617
/
string_to_lowercase_and_uppercase.cpp
60 lines (45 loc) · 1.25 KB
/
string_to_lowercase_and_uppercase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*program to convert string to lowercase and uppercase*/
#include<iostream>
#include<string>
using namespace std;
string lowercase(string s1){
for(int i=0;i<s1.size();++i)
{
if(s1[i]>=65 && s1[i]<=90)
s1[i]=s1[i]+32;//conversion to lowercase
}
return s1;
}
string uppercase(string s1)
{
for(int i=0;i<s1.size();++i)
{
if(s1[i]>=97 && s1[i]<=122)
{
s1[i]=s1[i]-32;//convertion to uppercase case
}
}
return s1;
}
int main()
{
string s1,lowercase_string,uppercase_string;
getline(cin,s1);
lowercase_string=lowercase(s1);//lowercase_string will contain the string with lowercase letter
uppercase_string=uppercase(s1);//uppercase_string will contain the string with uppercase letter
cout<<"Lowercase ->"<<lowercase_string<<endl;
cout<<"Uppercase ->"<<uppercase_string<<endl;
return 0;
}
/*
Test Case 1:
input - EloQuEnT
output - Lowercase ->eloquent
Uppercase ->ELOQUENT
Test Case 2:
input - DiVeRtIcuLaR
output - Lowercase ->diverticular
Uppercase ->DIVERTICULAR
Time complexity: O(n)
Space Complexity: O(n)
*/