P

@praveen11

swap even and odd bits

C++
4 years ago
#include <iostream> using namespace std; unsigned int swapBits(unsigned int n) { unsigned int odds = n & 0x55555555; unsigned int evens = n & 0xAAAAAAAA; odds <<= 1; evens >>= 1; return (odds | evens); }

largest number from the given vector elements

C++
4 years ago
#include <iostream> #include<vector> #include<string> #include<algorithm> using namespace std; int main() { int n; cin>>n; int input; vector<int> v;

given a range, print the numbers that are sum of cubes of two numbers

Python
4 years ago
""" given a range, print the numbers that are sum of cubes of two numbers """ import math a,b=map(int,input().split()) x=math.ceil(b**(1/3)) print(a,b,x) l1=[int(i)**3 for i in range(1,b+1)] ans=[]

printing first char of each word from the given input string from user

Python
4 years ago
l=[i for i in input().split()] n=[] for i in range(len(l)): n.append(l[i][0]) print(n)

most frequent character in a string

C++
4 years ago
#include <iostream> #include<map> #include<string> using namespace std; int main() { string s; cin>>s; map<char,int> m; for(int i=0;i<s.length();i++){ m[s[i]]++;

adding elements of two lists

Python
4 years ago
x=[10,20,30] y=[1,2,3] ans=[] for i in range(len(x)): ans.append(x[i]+y[i]) print(ans)

factorial using recursion

Python
4 years ago
def factorial(n): if(n==0 or n==1): return 1; else: return n*factorial(n-1) n=int(input()) print(factorial(n))

Find The Rankers codechef problem

C++
4 years ago
#include <iostream> #include<map> #include<vector> using namespace std; int main() { int n; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[i];

print the number in range 1 to N in lexicographical order

C++
4 years ago
/* Given N, print the numbers in the range N in lexicographical order Where lexicographical order means the order followed by the dictionary for suppose for value N=15, the lexicographical order in range 1 to N is 1 10 11 12 13 14 15 2 3 4 5 6 7 8 9 */ #include<iostream> #include<vector> #include<string>

Given an array of size N, print the array elements in along with their frequencies

C++
4 years ago
/* Given an array of size N, print the array elements in along with their frequencies */ #include <iostream> #include<map> using namespace std; int main() { map<int,int> m; int n;

Given N strings, q queries In each query who are given a string print the frequency of that string

C++
4 years ago
/* Given N strings, q queries In each query who are given a string print the frequency of that string 1<=N<=10^5 1<=|S|<=100 1<=q<=10^6 */ #include <iostream>

print the unique strings in lexiographical order with their frequenices from given input of N strings

C++
4 years ago
/* Given N strings, print the unique strings in lexiographical order with their frequenices 1<=N<=10^5 1<=|S|<=100 */ #include <iostream> #include<map> using namespace std; int main() {

find, erase, size, clear functions on map

C++
4 years ago
#include <iostream> #include<map> using namespace std; int main() { map<int,string> m; m[1]="hi"; m[2]="hello"; m[3]="thanks"; m[4]="namasthe"; for(auto i: m){

binary search stl

C++
4 years ago
#include<iostream> #include<vector> #include<algorithm> using namespace std; int main() { vector<int> v; int input; while(cin>>input){ v.push_back(input); }

initailising map (ordered)

C++
4 years ago
#include<iostream> #include<map> using namespace std; int main(){ map<int,string> m; m[1]="Praveen"; m[2]="Kumar"; m[3]="Adari"; cout<<"Key\tValues\n"; for(auto i:m){

Compare the Triplets

C++
4 years ago
#include<bits/stdc++.h> using namespace std; int main(){ int a[3],b[3]; for(int i=0;i<3;i++){ cin>>a[i]; } for(int i=0;i<3;i++){ cin>>b[i]; }

Factorial

C
4 years ago
#include<stdio.h> long long int factorial(int n){ if(n==0 || n==1) return 1; else return n*factorial(n-1); } int main(){

Printing Tokens

C
4 years ago
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { char *s; s = malloc(1024 * sizeof(char)); scanf("%[^\n]", s);

1D Arrays in C

C
4 years ago
#include<stdio.h> int main(){ int n; scanf("%d",&n); int a[n]; for(int i=0;i<n;i++){ scanf("%d",&a[i]); } int sum=0; for(int i=0;i<n;i++){

Array Reversal

C
4 years ago
#include<stdio.h> int main(){ int n; scanf("%d",&n); int a[n]; for(int i=0;i<n;i++){ scanf("%d",&a[i]); } for(int i=n-1;i>=0;i--){ printf("%d ",a[i]);