-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring.cpp
133 lines (101 loc) · 2.85 KB
/
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
/*
//Input Output
// string str;
// cin>>str;
// cout<<str;
// string str1(5,'n');
// cout<<str1;
// string str2 = "Neeraj Yadav";
// cout<<str2;
// string str3;
// getline(cin, str3); //For taking input with spaces
// cout<<str3;
//Operations and functions
string s1 = "Nee";
string s2 = "raj";
// // cout<<s1+s2<<endl; //without changing s1 or s2
// s1.append(s2); // or s1 = s1+s2;
// cout<<s1;
// cout<<s1[0]<<" "<<s2[1];
// s1.clear(); // clear out string value
// cout<<s1;
// cout<<s2.compare(s1); //return 0 if equal else 1
// cout<<s1.empty(); //return 0 if empty else 1
string str = "Helllllo";
// str.erase(2,3); // remove 3 character from index 2
// cout<<str;
// cout<<str.find("ell"); //return index of first element of substring if find
// cout<<s1.insert(1, s2); //insert s2 in s1 at index = 1
// cout<<s1.length(); //return length of string
// // or s1.size();
// string subSt = str.substr(5, 3); //substring from index 5 with 3 character
// cout<<subSt;
// string s3 = "786";
// int x = stoi(s3); //convert string to integer
// cout<<x;
// int x = 786;
// cout<<to_string(x); //convert integer to string
// sort(s1.begin(), s1.end());
// cout<<s1;
// string s4 = "jghgKAghgj";
// sort(s4.begin(),s4.end()); // sort the string to AKgggghhjj
// cout<<s4;
*/
//String Questions
/*
// // Convert string into upper case
string s1 = "NeerAj";
// for(int i = 0; i < s1.size(); i++){
// if(s1[i] >= 'a' && s1[i] <= 'z')
// s1[i] -= 32;
// }
// cout<<s1;
// or
transform (s1.begin(), s1.end(), s1.begin(), ::toupper);
cout<<s1;
*/
/*
// // Convert string into lower case
string s1 = "NeerAj";
// for(int i = 0; i < s1.size(); i++){
// if(s1[i] >= 'A' && s1[i] <= 'Z')
// s1[i] += 32;
// }
// cout<<s1;
// or
transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
cout<<s1;
*/
/*
// // Biggest nummber from numeric string
string s = "4986";
sort(s.begin(), s.end(), greater<int>());
cout<<s;
*/
/*
// // Most frequency
string s = "hjjfhugfdsgdjjjcsgdialgjcdsb";
int arr[26];
for(int i = 0; i < 26; i++){
arr[i] = 0;
}
for(int i = 0; i < s.size(); i++){
arr[s[i] - 'a']++;
}
int maxFreq = 0;
char ans = 'a';
for(int i = 0; i < 26; i++){
if(arr[i] >maxFreq){
maxFreq = arr[i];
ans = i + 'a';
}
}
cout<<maxFreq<<"\n"<<ans;
*/
return 0;
}