PHP code for String Tokenize
<?php
$string = "Hello Kamal. How are you Doing?";
$token = strtok($string, " ");
while ($token !== false)
{
echo "$token<br>";
$token = strtok(" ");
}
?>
Learn Android very Easily and Step by Step with this blog.
ππ»π Romantic DP for Whatsapp π₯°π
PHP code for String Tokenize
<?php
$string = "Hello Kamal. How are you Doing?";
$token = strtok($string, " ");
while ($token !== false)
{
echo "$token<br>";
$token = strtok(" ");
}
?>
What is Anagram : An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once
#include <iostream>
#include <string.h>
using namespace std;
void checkAnagrams(char str1[],char str2[])
{
int hash[26];
int i;
for( i=0;i<26;i++)
hash[i]=0;
for(i=0;i<strlen(str1);i++)
{
hash[str1[i]-97]++;
}
for(i=0;i<strlen(str2);i++)
{
hash[str2[i]-97]--;
}
for(i=0;i<26;i++)
{
if(hash[i]!=0)
break;
}
if(i==26)
cout<<"Strings are anagrams";
else
cout<<"Strings are not anagrams";
}
int main(int argc, char *argv[])
{
checkAnagrams("madam curie","radium came");
return EXIT_SUCCESS;
}
Rat in Maze problem : This is a famous problem solving coding question. There is a grid filled with 1 and 0, There is a rat at position 0,0. He has to reach at the last point of Grid and the Rat can move to block having value 1.
Print the path the will take to reach.
#include <iostream>
using namespace std;
#define N 5
int path[N][N]={1,1,1,1,1,
0,0,1,0,1,
1,1,1,1,1,
1,0,1,0,0,
1,1,1,1,1
};
int sol[N][N];
bool isValid(int row,int col)
{
if(row>=0&&col>=0&&row<N&&col<N&&path[row][col]==1&&sol[row][col]==0)
return true;
else
return false;
}
bool solveRatInMaze(int row,int col)
{
if(row==N-1&&col==N-1)
{
sol[row][col]=1;
return true;
}
// int i=row,j= col;
if(isValid(row,col)==true)
{
sol[row][col]=1;
// move right
if(solveRatInMaze(row+1,col)==true)
return true;
if(solveRatInMaze(row,col+1)==true)
return true;
if(solveRatInMaze(row+1,col)==true)
return true;
if(solveRatInMaze(row-1,col)==true)
return true;
if(solveRatInMaze(row,col-1)==true)
return true;
sol[row][col]=0;
}
else
return false;
return false;
}
int main(int argc, char *argv[])
{
int i,j;
for( i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
sol[i][j]=0;
}
}
if(solveRatInMaze(0,0)==true)
{
for( i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
printf("%d ",sol[i][j]);
}
printf("\n");
}
}
else
printf("There is no path");
return EXIT_SUCCESS;
}
Output :
1 1 1 0 0
0 0 1 0 0
0 0 1 0 0
0 0 1 0 0
0 0 1 1 1
#include <iostream>
#include <math.h>
using namespace std;
int add(int a,int b)
{
int num=0,carry=0,p=0;
int abit,bbit,numbit;
while(a!=0||b!=0)
{
abit=a&1;
bbit=b&1;
numbit=abit^bbit^carry;
carry=(abit&bbit)||(abit&carry)||(bbit&carry);
num=num+numbit*(int)pow(2,p);
p++;
a=a>>1;
b=b>>1;
}
if(carry==1)
num=num+(int)pow(2,p);
return num;
}
int main(int argc, char *argv[])
{
printf("%d",add(70,40));
return 0;
}
Output :
110
C++ Code
int add1(int num)
{
int mask=1;
if(num>=0)// if number is +ve
{
while(true)
{
if(num&mask)
{
num=num^mask;
}
else
{
num=num^mask;
break;
}
mask=mask<<1;
}
return num;
}
else // if number bis -ve
{
num=abs(num);
while(true)
{
if(num&mask)
{
num=num^mask;
break;
}
else
{
num=num^mask;
}
mask=mask<<1;
}
return (-num);
}
}
int main(int argc, char *argv[])
{
cout<<add1(12563);
return EXIT_SUCCESS;
}
C++ Code
#include <iostream>
using namespace std;
void arrange(int a[],int n)
{
int i=0,zero=-1,one=-1;
while(i<n&&zero<n&&one<n)
{
if(i%2!=0) // if odd place
{
if(a[i]!=0)
{
if(zero==-1)
zero=i+1;
while(a[zero]!=0&&zero<n)
zero++;
if(a[zero]==0)
{
a[zero]=1;
a[i]=0;
zero++;
}
}
}
else
{
if(a[i]!=1)
{
if(one==-1)
one=i+1;
while(a[one]!=1&&one<n)
one++;
if(a[one]==1)
{
a[one]=0;
a[i]=1;
one++;
}
}
}
i++;
}
}
int main(int argc, char *argv[])
{
int a[]={1,0,1,1,0,0,1,1,1,0};
int n=10;
arrange(a,n);
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
return EXIT_SUCCESS;
}
C ++ Code
#include <iostream>
using namespace std;
int find(int a[],int n)
{
int low=0,up=n;
int mid;
while(low<=up)
{
mid=(up+low)/2;
if(a[mid]<a[mid-1]&&a[mid]<a[mid+1])
return a[mid];
else if(a[mid]>a[low])
low=mid+1;
else
up=mid-1;
}
return 0;
}
int main()
{
int a[]={14,16,18,2,3,4,5,6};
int num=find(a,7);
printf("%d",num);
return 0;
}
Code :
public class Test {
public static void main(String a[])
{
GregorianCalendar gc = new GregorianCalendar();
System.out.print(gc.getTime());
}
}
Output :
Fri Sep 30 10:38:51 IST 2022
<?php // Initializing a variable with filename $file = 'myfilename.jpg' ; // Extracting only filename using constants $fileWithoutExt = pathinfo ( $file , PATHINFO_FILENAME); // Printing the result echo $ fileWithoutExt; ?>
Output
|