-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_challenges.cpp
70 lines (57 loc) · 1.18 KB
/
string_challenges.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
61
62
63
64
65
66
67
68
69
70
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
//string to upper case
string s1="skaGuirr";
for(int i=0;i<s1.size();i++)
{
if (s1[i]>='a' && s1[i]<='z')
{
s1[i] -=32;
}
}
cout<<s1<<endl;
//string to lower case
string s2="DKGHDGKdkh";
for (int i = 0; i < s2.size(); i++)
{
if(s2[i]>='A' && s2[i]<='Z')
{
s2[i] +=32;
}
}
cout<<s2<<endl;
//inbuild function to do similar work
string str="fkhshgj";
transform(str.begin(), str.end(), str.begin(), ::toupper);
cout<<str<<endl;
//form the biggest number from the given numeric string
string biggest="798";
sort(biggest.begin(),biggest.end(), greater<int>());
cout<<biggest<<endl;
//maximum occuring character in string
string maximum="hdvbdjf";
int freq[26];
for(int i=0;i<26;i++)
{
freq[i]=0;
}
for (int i = 0; i < maximum.size(); i++)
{
freq[maximum[i]-'a']++;
}
char ans='a';
int maxF=0;
for(int i=0;i<26;i++)
{
if (freq[i]>maxF)
{
maxF=freq[i];
ans=i+'a';
}
}
cout<<maxF<<" "<<ans<<endl;
return 0;
}