-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChange_The_String.cpp
60 lines (45 loc) · 1.23 KB
/
Change_The_String.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
Link:- https://practice.geeksforgeeks.org/problems/change-the-string3541/1
Given a string S, the task is to change the complete string to Uppercase or Lowercase depending upon the case for the first character.
Input:
S = "abCD"
Output: abcd
Explanation: The first letter (a) is
lowercase. Hence, the complete string
is made lowercase.
Input:
S = "Abcd"
Output: ABCD
Explanation: The first letter (A) is
uppercase. Hence, the complete string
is made uppercase.
string modify (string s)
{
// your code here
string ans="";
if(s[0]>='a'&&s[0]<='z')
{
for(int i=0;i<s.length();i++)
ans=ans+(char)tolower(s[i]);
}
else
{
for(int i=0;i<s.length();i++)
ans=ans+(char)toupper(s[i]);
}
return ans;
}
/************* 2nd Approach ******************/
string modify (string s)
{
// your code here
string ans="";
if(s[0]>='a'&&s[0]<='z')
{
transform(s.begin(), s.end(), s.begin(), ::tolower);
}
else
{
transform(s.begin(), s.end(), s.begin(), ::toupper);
}
return s;
}