top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to find all palindrome strings in a text file using C?

+4 votes
411 views
How to find all palindrome strings in a text file using C?
posted Jan 21, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
#include<stdio.h>
#include<conio.h>
int stpal(char str[50], int st, int ed);
void main()
{
char str[50];
int pal = 0, len = 0, i, start = 0, end;
clrscr();
printf(“\n\n\t ENTER A SENTENCE…: “);
gets(str);
while(str[len]!=’\0′)
len++;
len–;
for(i=0;i<=len;i++)
{
if((str[i] == ‘ ‘ && str[i+1] != ‘ ‘) || i == len)
{
if(i == len)
end = i;
else
end = i – 1;
if( stpal (str, start, end ) )
pal++;
start = end + 2;
}
}
printf(“\n\n\t THE TOTAL NUMBER OF PALINDROMES ARE..: %d”,pal);
getch();
}
int stpal(char str[50], int st, int ed)
{
int i, pal=0;
for(i=0; i<=(ed-st)/2; i++)
{
if(str[st+i] == str[ed-i])
pal = 1;
else
{
pal = 0;
break;
}
}
return pal;
}
answer Jan 22, 2016 by Shivaranjini
Similar Questions
+6 votes

Take input 'n' as number of strings and find the common alphabet among them.
For example:
Input:

Number of Strings - 3
List of Strings - 
abcdde
baccd
eeabg

output:

2   

as 'a' and 'b' are only two common alphabet among those three strings

+4 votes

To do this, you have to follows two rules:

  1. You can reduce the value of a letter, e.g. you can change d to c, but you cannot change c to d.
  2. In order to form a palindrome, if you have to repeatedly reduce the value of a letter, you can do it until the letter becomes a. Once a letter has been changed to a, it can no longer be changed.

for example: for string abc
abc->abb->aba
total 2 number of operations needed to make it a palindrome.

+4 votes

Given a dictionary of strings and another string find out if the string is an exact match to some words in the dictionary or varies at most in only one place of some word of the dictionary?

...