Skip to content

Commit 7801be1

Browse files
committed
gfg
1 parent 3e5b507 commit 7801be1

File tree

5 files changed

+203
-0
lines changed

5 files changed

+203
-0
lines changed

convert_to_lowercase.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
/*
3+
Link:- https://practice.geeksforgeeks.org/problems/java-convert-string-to-lowercase2313/1
4+
The task is to convert characters of string to lowercase.
5+
6+
7+
Input: S = "ABCddE"
8+
Output: "abcdde"
9+
Explanation: A, B, C and E are converted to
10+
a, b, c and E thus all uppercase characters
11+
of the string converted to lowercase letter.
12+
13+
*/
14+
15+
string toLower(string s)
16+
{
17+
// code here
18+
string ans = "";
19+
for (int i = 0; i < s.length(); i++)
20+
{
21+
if (s[i] >= 'A' && s[i] <= 'Z')
22+
s[i] = s[i] + 32;
23+
ans = ans + s[i];
24+
// ans=ans+ (char)tolower(s[i]);
25+
}
26+
return ans;
27+
}
28+
29+
/*
30+
31+
//Using tolower() function
32+
33+
string toLower(string s) {
34+
35+
string ans="";
36+
for(int i=0;i<s.length();i++)
37+
{
38+
ans=ans+ (char)tolower(s[i]);
39+
}
40+
return ans;
41+
}
42+
43+
*/
44+
45+
/*
46+
/***** bonus *****
47+
48+
//Convert to CamelCase
49+
s[0]=s[0]-32;
50+
for(int i=0;i<s.size();i++)
51+
{
52+
if(s[i]==' ')
53+
{
54+
s[i+1]=s[i+1]-32;
55+
}
56+
}
57+
return s;
58+
*/

display_longest_name.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Given a list of names, display the longest name.
3+
4+
link:- https://practice.geeksforgeeks.org/problems/display-longest-name0853/1
5+
6+
Input:
7+
N = 5
8+
names[] = { "Geek", "Geeks", "Geeksfor",
9+
"GeeksforGeek", "GeeksforGeeks" }
10+
11+
Output:
12+
GeeksforGeeks
13+
14+
15+
*/
16+
17+
int l=0;
18+
string ans="";
19+
string longest(string names[], int n)
20+
{
21+
for(int i=0;i<n;i++)
22+
{
23+
if(names[i].length()>=l)
24+
{
25+
l=names[i].length();
26+
ans=names[i];
27+
}
28+
}
29+
return ans;
30+
}

equilibrium_point.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
NOTE:- it is imp ARRAY QUESTION NOT STRING
3+
link:- https://practice.geeksforgeeks.org/problems/equilibrium-point-1587115620/1
4+
5+
problem:- Given an array A of n positive numbers. The task is to find the first Equilibium Point in the array.
6+
Equilibrium Point in an array is a position such that the sum of elements before it is equal to the sum of elements after it.
7+
8+
Input:
9+
n = 5
10+
A[] = {1,3,5,2,2}
11+
Output: 3
12+
Explanation: For second test case
13+
equilibrium point is at position 3
14+
as elements before it (1+3) =
15+
elements after it (2+2).
16+
17+
Input:
18+
n = 1
19+
A[] = {1}
20+
Output: 1
21+
Explanation:
22+
Since its the only element hence
23+
its the only equilibrium point.
24+
25+
*/
26+
27+
// { Driver Code Starts
28+
#include <iostream>
29+
using namespace std;
30+
31+
32+
// } Driver Code Ends
33+
class Solution{
34+
public:
35+
// Function to find equilibrium point in the array.
36+
// a: input array
37+
// n: size of array
38+
int equilibriumPoint(long long arr[], int n) {
39+
int t_sum=0,sum1=0,sum2=0;
40+
if(n==1)
41+
{
42+
return 1;
43+
}
44+
for(int i=0;i<n;i++)
45+
{
46+
t_sum+=arr[i];
47+
}
48+
for(int i=1;i<n;i++)
49+
{
50+
sum1=sum1+arr[i-1];
51+
sum2=t_sum-sum1-arr[i];
52+
53+
if(sum1==sum2)
54+
{
55+
return i+1;
56+
}
57+
58+
}
59+
return -1;
60+
}
61+
62+
};
63+

reverse_string.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ string reverseWord(string str){
1616
{
1717
s=s+str[i];
1818
}
19+
20+
1921
return s;
2022
//Your code here
2123
}
24+
25+
/* using swap */
26+
// for(int i=0;i<s.length()/2;i++)
27+
// {
28+
// swap(s[i],s[s.length()-i-1]);
29+
// }

reversing_the_vowel.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Link:-https://practice.geeksforgeeks.org/problems/reversing-the-vowels5304/1
3+
problem:- Given a string consisting of lowercase english alphabets, reverse only the vowels present in it and print the resulting string.
4+
5+
Input:
6+
S = "geeksforgeeks"
7+
Output: geeksforgeeks
8+
Explanation: The vowels are: e, e, o, e, e
9+
Reverse of these is also e, e, o, e, e.
10+
11+
Input:
12+
S = "practice"
13+
Output: prectica
14+
Explanation: The vowels are a, i, e
15+
Reverse of these is e, i, a.
16+
17+
*/
18+
19+
string modify (string s)
20+
{
21+
//code here.
22+
string vowel="";
23+
for(int i=0;i<s.length();i++)
24+
{
25+
if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u')
26+
{
27+
vowel+=s[i];
28+
}
29+
}
30+
31+
32+
int n=vowel.length();
33+
34+
for(int i=0;i<s.length();i++)
35+
{
36+
if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u')
37+
{
38+
s[i]=vowel[n-1];
39+
n--;
40+
}
41+
}
42+
43+
return s;
44+
}

0 commit comments

Comments
 (0)