PHP – Split sentence into words


Q.) Ignore ‘Spaces’ and splitĀ sentenceĀ into words and store into array

Function:

<?php
function splitIt($s){
			$arr = array('.',',');
			$s = str_replace($arr," ",$s);
			$s = preg_replace("/( )+/", " ", $s);
			$s = preg_replace("/^( )+/", "", $s);
			$s = preg_replace("/( )+$/", "", $s);
			$tokens = explode(" ",$s);
			return $tokens;
		}
?>

Input:

 <?php
 $answer = splitIt("   hello world. prt this sentence,please  ");
 print_r($answer);
?>

Output:

 Array ( 
    [0] => hello
    [0] => world
    [0] => prt
    [0] => this
    [0] => sentence
    [0] => please
)

The number which is prime and also palindrome.


After many days of gap… Ā back to blogging…….

Q.)Ā An integer is said to be a palindrome if it is equal to its reverse. For example, 79197 and 324423 areĀ palindromes. In this task you will be given an integer N, 1 ā‰¤ N ā‰¤ 1000000. You must find the smallestĀ integer M ā‰„ N such that M is a prime number and M is a palindrome.Ā For example, if N is 31 then the answer is 101.

Input format
A single integer N, (1 ā‰¤ N ā‰¤ 1000000), on a single line.
Output format
Your output must consist of a single integer, the smallest prime palindrome greater than or equal to N

Sol.)

#include<stdio.h>
void main()
{
   long int a;
   printf("Enter number: ");
   scanf("%li",&a);
   if(a <= 1000000)
    while(1)
    {
     if(palindrome(a)){
     if(prime(a)) {printf("Number is: %d",a);getch();return;}
    }
  a=a+1;
}
else printf("Plz enter number less than 1000000 next time");
getch();
}
int prime(long int a){
long int i;
for(i=2;i<=a/2;i++) if(a%i==0)return 0;

return 1;
}

int palindrome(long int a){
  long int temp=a,reverse=0;
 while( temp != 0 ){
  reverse = reverse * 10;
  reverse = reverse + temp%10;
  temp = temp/10;
 }
  if(reverse == a) return 1;
  else return 0;
}

Shivaji varma… šŸ˜€

Design buttons using css


<html>
<head>

<style>
.navBtn{
	background-color:#EAECED;
	color:#565656;
	width:80px;

	font-family:"Times New Roman", Times, serif;
	font-size:larger;
	font-weight:bold;
	text-align:center;
	padding:6px;

	cursor:pointer;

	border-radius: 4px 4px 4px 4px;
}

.navBtn a,a:visited{
	text-decoration:inherit;
	color:inherit;
}

.navBtn:hover{
	background-color:#1EB4DA;
	color:#EAECED;
}

.navActive{
	background-color:#FF3C3C;
	color:#EAECED;
}

</style>
</head>
<body>
 <div class="navBtn">1</div>
 <br>
 <div class="navBtn">2</div>
 <br>
 <div class="navBtn">3</div>
</body>
</html>

Recursive Descent Parsing


The following c program parser the given string for the given grammar::

E->E+T

E->T

T->T*F

T->F

F->(E)

F->i


Before writing writing recursive descent parser firstĀ eliminate leftĀ recursion and left factoring.

E->TEplus

Eplus->+TEplus /Ā āˆˆ (epsilon)

T ->FTplus

Tplus->*FTplusĀ /Ā āˆˆ (epsilon)

F-> (E)

F-> i


#include<stdio.h>
#include<string.h>
char string[' '];
int len;
int pos=0;
int E();
int Eplus();
int T();
int Tplus();
int F();
int main()
{
printf("Enter the string:: ");
scanf("%s",&string);
len=strlen(string);
if(E()==0) printf("\nNot Accepted");
else if(pos<len) {printf("\nNot Accepted");}
else printf("\nAccepted");
printf("\n");
return 0;
}
int E()
{
if(T()==0) return 0;
if(Eplus()==0) return 0;
return 1;
}
int Eplus()
{
if(string[pos]=='+')
{ pos++;
if(T()==0) return 0;
if(Eplus()==0) return 0;
}
return 1;
}
int T()
{
if(F()==0) return 0;
if(Tplus()==0) return 0;
return 1;
}
int Tplus()
{
if(string[pos]=='*')
{ pos++;
if(F()==0) return 0;
if(Tplus()==0) return 0;
}
return 1;
}
int F()
{
if(string[pos]=='('){
pos++;
if(E()==0) return 0;
if(string[pos]==')') pos++;
else return 0;
}
else if(string[pos]=='i'){
pos++;}
else {return 0;}
return 1;
}

Don’t copy the code directly from this page it may contain HTML meta content.

Just download this text file(code)>>>>Download<<<<