Skip to content

Commit d1ae849

Browse files
committed
22/10/2022
1 parent 0d5b6ea commit d1ae849

8 files changed

+346
-0
lines changed

Change_The_String.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
Link:- https://practice.geeksforgeeks.org/problems/change-the-string3541/1
3+
4+
Given a string S, the task is to change the complete string to Uppercase or Lowercase depending upon the case for the first character.
5+
6+
Input:
7+
S = "abCD"
8+
Output: abcd
9+
Explanation: The first letter (a) is
10+
lowercase. Hence, the complete string
11+
is made lowercase.
12+
13+
Input:
14+
S = "Abcd"
15+
Output: ABCD
16+
Explanation: The first letter (A) is
17+
uppercase. Hence, the complete string
18+
is made uppercase.
19+
20+
21+
string modify (string s)
22+
{
23+
// your code here
24+
string ans="";
25+
if(s[0]>='a'&&s[0]<='z')
26+
{
27+
for(int i=0;i<s.length();i++)
28+
ans=ans+(char)tolower(s[i]);
29+
}
30+
else
31+
{
32+
for(int i=0;i<s.length();i++)
33+
ans=ans+(char)toupper(s[i]);
34+
}
35+
return ans;
36+
}
37+
38+
/************* 2nd Approach ******************/
39+
40+
41+
string modify (string s)
42+
{
43+
// your code here
44+
string ans="";
45+
if(s[0]>='a'&&s[0]<='z')
46+
{
47+
48+
transform(s.begin(), s.end(), s.begin(), ::tolower);
49+
50+
51+
}
52+
else
53+
{
54+
55+
transform(s.begin(), s.end(), s.begin(), ::toupper);
56+
57+
58+
}
59+
return s;
60+
}

Keypad_Typing.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
3+
Link:- https://practice.geeksforgeeks.org/problems/keypad-typing0119/1?
4+
5+
problem:-
6+
7+
1->
8+
2-> ABC
9+
3-> DEF
10+
4-> GHI
11+
5-> JKL
12+
6-> MNO
13+
7-> pQRS
14+
8-> TUV
15+
9-> WXYZ
16+
17+
Input:
18+
S = geeksforgeeks
19+
Output: 4335736743357
20+
Explanation:geeksforgeeks is 4335736743357
21+
in decimal when we type it using the given
22+
keypad.
23+
24+
Input:
25+
S = geeksquiz
26+
Output: 433577849
27+
Explanation: geeksquiz is 433577849 in
28+
decimal when we type it using the given
29+
keypad.
30+
31+
*/
32+
33+
string printNumber(string s, int n)
34+
{
35+
//code here
36+
unordered_map <char,string> mapping;
37+
38+
mapping['a']="2";
39+
mapping['b']="2";
40+
mapping['c']="2";
41+
mapping['d']="3";
42+
mapping['e']="3";
43+
mapping['f']="3";
44+
mapping['g']="4";
45+
mapping['h']="4";
46+
mapping['i']="4";
47+
mapping['j']="5";
48+
mapping['k']="5";
49+
mapping['l']="5";
50+
mapping['m']="6";
51+
mapping['n']="6";
52+
mapping['o']="6";
53+
mapping['p']="7";
54+
mapping['q']="7";
55+
mapping['r']="7";
56+
mapping['s']="7";
57+
mapping['t']="8";
58+
mapping['u']="8";
59+
mapping['v']="8";
60+
mapping['w']="9";
61+
mapping['x']="9";
62+
mapping['y']="9";
63+
mapping['z']="9";
64+
mapping[' ']="0";
65+
66+
string ans="";
67+
for(int i=0;i<s.length();i++)
68+
{
69+
ans=ans+mapping[s[i]];
70+
}
71+
return ans;
72+
}

Merge_Two_string_charbyChar.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Problem:- Given two strings S1 and S2 as input, the task is to merge them alternatively i.e. the first character of S1 then the first character of S2 and so on till the strings end.
3+
4+
Link:- https://practice.geeksforgeeks.org/problems/merge-two-strings2736/1
5+
6+
Input:
7+
S1 = "Hello" S2 = "Bye"
8+
Output: HBeylelo
9+
Explanation: The characters of both the
10+
given strings are arranged alternatlively.
11+
12+
Input:
13+
S1 = "abc", S2 = "def"
14+
Output: adbecf
15+
Explanation: The characters of both the
16+
given strings are arranged alternatlively.
17+
18+
*/
19+
20+
string merge (string s1, string s2)
21+
{
22+
// your code here
23+
string ans="";
24+
int i=0,j=0;
25+
while(i<s1.length() || j<s2.length())
26+
{
27+
if(i!=s1.length())
28+
{
29+
ans=ans+s1[i];
30+
i++;
31+
}
32+
if(j!=s2.length())
33+
{
34+
ans=ans+s2[j];
35+
j++;
36+
}
37+
}
38+
return ans;
39+
}

Red_OR_Green.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Link:- https://practice.geeksforgeeks.org/problems/red-or-green5711/1
3+
Problem:- Find out the minimum number of characters you need to change to make the whole string of the same colour.
4+
5+
Input:
6+
N=5
7+
S="RGRGR"
8+
Output:
9+
2
10+
Explanation:
11+
We need to change only the 2nd and
12+
4th(1-index based) characters to 'R',
13+
so that the whole string becomes
14+
the same colour.
15+
16+
Input:
17+
N=7
18+
S="GGGGGGR"
19+
Output:
20+
1
21+
Explanation:
22+
We need to change only the last
23+
character to 'G' to make the string
24+
same-coloured.
25+
*/
26+
27+
int RedOrGreen(int n,string s) {
28+
//code here
29+
int count1=0,count2=0;
30+
for(int i=0;i<n;i++)
31+
{
32+
if(s[i]=='R')
33+
{
34+
count1++;
35+
}
36+
else
37+
{
38+
count2++;
39+
}
40+
}
41+
return min(count1,count2);
42+
}

Remove_Consonants_from_string.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Link:-https://practice.geeksforgeeks.org/problems/c-program-to-remove-consonants-from-a-string1945/1
2+
Given a string S, remove all consonants and print the modified string that contains vowels only.
3+
4+
Input
5+
S = "abEkipo"
6+
Output
7+
aEio
8+
Explanation : a, E, i, o are only vowels in the string.
9+
Example 2:
10+
11+
Input
12+
S = "rrty"
13+
Output
14+
No Vowel
15+
Explanation: There are no vowels.
16+
17+
18+
string removeConsonants(string s){
19+
//complete the function heredef removeConsonants(s):
20+
string ans="";
21+
for(int i=0;i<s.length();i++)
22+
{
23+
if(s[i]=='a' || s[i]=='e' || s[i]=='o' || s[i]=='u' || s[i]=='i' || s[i]=='A' || s[i]=='E' || s[i]=='O' || s[i]=='U' || s[i]=='I')
24+
{
25+
ans=ans+s[i];
26+
}
27+
}
28+
if(ans=="")
29+
{
30+
return "No Vowel";
31+
}
32+
else
33+
return ans;
34+
}

ZNote.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
ascii value
2+
3+
48 to 57 - Number
4+
65 to 90 - uppercase [(s[0]>='a'&&s[0]<='z']
5+
97 to 122 - lowercase
6+
7+
lowercase = lowercase + 32
8+
9+
10+
inbuilt Method:-
11+
12+
toupper:- for(int i=0;i<s.length();i++)
13+
ans=ans+(char)tolower(s[i]);
14+
tolower
15+
16+
17+
Transform:- transform(s.begin(), s.end(), s.begin(), ::tolower);
18+
transform(s.begin(), s.end(), s.begin(), ::toupper);
19+
20+
Find:- s1.find(s2[i]):- find s2[i] in s1
21+
22+
23+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Link:- https://practice.geeksforgeeks.org/problems/extract-maximum2943/1
2+
3+
Given a alphanumeric string S, extract maximum numeric value from S.
4+
5+
Input:
6+
S = 100klh564abc365bg
7+
Output: 564
8+
Explanation: Maximum numeric value
9+
among 100, 564 and 365 is 564.
10+
Example 2:
11+
12+
Input:
13+
S = abcdefg
14+
Output: -1
15+
Explanation: Return -1 if no numeric
16+
value is present.
17+
18+
19+
int extractMaximum(string s)
20+
{
21+
22+
int num=0,max=-1;
23+
for(int i=0;i<s.length();i++)
24+
{
25+
if(s[i]>=48 && s[i]<=57)
26+
{
27+
num = num*10 + (s[i]-'0');
28+
if(num>max)
29+
{
30+
max=num;
31+
}
32+
}
33+
else
34+
{
35+
num=0;
36+
}
37+
38+
}
39+
return max;
40+
}

longest_1_count_in_string.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
Link:- https://practice.geeksforgeeks.org/problems/longest-substring-containing-1/1
3+
4+
count max 1 consecutive possile
5+
6+
Input:
7+
2
8+
110
9+
11101110
10+
Output:
11+
2
12+
3
13+
14+
15+
int maxlength( string s)
16+
{
17+
// your code here
18+
int max=0,count=0;;
19+
for(int i=0;i<s.length();i++)
20+
{
21+
if(s[i]=='1')
22+
{
23+
count++;
24+
if(count>max)
25+
{
26+
max=count;
27+
}
28+
}
29+
else
30+
{
31+
32+
count=0;
33+
}
34+
}
35+
return max;
36+
}

0 commit comments

Comments
 (0)