Codes
Codes
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int i = 0;
int bin = 0;
int num;
while (n > 0) {
num = n % 10;
if (num == 1) {
bin += pow(2, i);
}
return 0;
}
int main()
{
int n;
cin>>n;
vector<int> arr;
int m=0;
while( n > 0)
{
if(n % 2 == 0)
{
arr.push_back(0);
}
else
arr.push_back(1);
n = n/2;
m++;
}
#include<bits/stdc++.h>
using namespace std;
if(str.length() == 0)
{
cout<<"";
return;
}
else if (str.length() == 1)
{
cout<<single_digit[str[0] - '0']<<endl;
return;
}
int len=str.length();
}
len--;
}
else{
int main()
{
string str;
cin>>str;
convert_dec_to_word(str);
return 0;
}
STRINGS
1. Palindrome string
#include<bits/stdc++.h>
using namespace std;
int main(){
string str;
cin>>str;
int n = str.length();
int flag = 0;
if(flag == 1)
cout<<"String is not palindrome";
else
cout<<"String is palindrome";
}
Point of mistakes:
Getline str instead of cin
For spaces comparison use ‘ ‘ instead of “ “ .
#include<bits/stdc++.h>
using namespace std;
int main(){
string str;
getline(cin, str);
int n = str.length();
int vowels=0;
int consonants=0;
int space=0;
cout<<"Vowels"<<vowels<<endl;
cout<<"Consonants"<<consonants<<endl;
cout<<"White Spaces"<<space;
}
3. ASCII Value
For single character string
#include<bits/stdc++.h>
using namespace std;
cout<<int(str);
int main(){
char str;
cin>>str;
value(str);
}
For input string
#include<bits/stdc++.h>
using namespace std;
int main(){
string str;
cin>>str;
value(str);
}
4. Remove vowels
O(N^2)
#include<bits/stdc++.h>
using namespace std;
int main(){
string str;
getline(cin, str);
int n = str.length();
if(str[i] == 'a' || str[i] == 'e' ||str[i] == 'i' ||str[i] == 'o' ||str[i] == 'u'
||str[i] == 'A' ||str[i] == 'E' ||str[i] == 'I' ||str[i] == 'O' ||str[i] == 'U'){
for(int j=i; j<n; j++)
{
str[j]=str[j+1];
}
}
}
O(N)
#include<bits/stdc++.h>
using namespace std;
if(str[i] == 'a' || str[i] == 'e' ||str[i] == 'i' ||str[i] == 'o' ||str[i] == 'u'
||str[i] == 'A' ||str[i] == 'E' ||str[i] == 'I' ||str[i] == 'O' ||str[i] == 'U')
{
str=str.substr(0, i) + str.substr(i+1);
i--;
}
}
return str;
int main(){
string str;
getline(cin, str);
cout<<remove_vowels(str);
5. Remove spaces
#include<bits/stdc++.h>
using namespace std;
int main(){
string str;
getline(cin, str);
cout<<remove_spaces(str);
}
6.Remove spaces
#include<bits/stdc++.h>
using namespace std;
return ans;
}
int main(){
string str;
getline(cin, str);
cout<<remove_characters(str);
}
7.Reverse string
#include<bits/stdc++.h>
using namespace std;
return ans;
}
int main(){
string str;
getline(cin, str);
cout<<reverse_string(str);
}
8. Remove brackets
#include<bits/stdc++.h>
using namespace std;
return str;
}
int main()
{
string str;
getline(cin, str);
cout<<remove_brackets(str);
}
int main(){
string str;
getline(cin, str);
cout<<string_sum(str); // aage krna hai
}
#include<bits/stdc++.h>
using namespace std;
return str;
}
int main()
{
string str;
getline(cin, str);
cout<<capitalize_string(str);
}
11.