#include<iostream>
#include<list>
#include<string>
#include<vector>
void to_upper(std::string& str)
{
for(std::string::iterator it=str.begin(); it!=str.end(); ++it )
if( *it>='a' && *it<='z' )
*it-=32;
}
void to_lower(std::string& str)
{
for(std::string::iterator it=str.begin(); it!=str.end(); ++it )
if( *it>='A' && *it<='Z' )
*it+=32;
}
void to_ascending(std::string& str)
{
for(size_t i=1; i<str.size(); ++i)
{
char c=str[i];
int hole=i;
while(hole && c<str[hole-1])
{
str[hole]=str[hole-1];
--hole;
}
str[hole]=c;
}
}
void to_descending(std::string& str)
{
for(size_t i=1; i<str.size(); ++i)
{
char c=str[i];
int hole=i;
while( hole && c>str[hole-1] )
{
str[hole]=str[hole-1];
--hole;
}
str[hole]=c;
}
}
void to_reverse(std::string& str)
{
std::string rev;
for(std::string::reverse_iterator it=str.rbegin(); it!=str.rend(); ++it )
rev+=*it;
str=rev;
}
bool palindromes(std::string& str, std::list<std::string>& lst )
{
lst.clear();
std::vector<int> v;
std::string copy( str );
to_lower( copy );
size_t pos;
for(pos=0; pos<copy.size(); ++pos)
{
char& c=copy[pos];
if((c>='a' && c<='z') (c>='A' && c<='Z'))
{
if(v.size())
v.push_back(-1);
v.push_back(pos);
}
}
for(pos=1; pos<v.size()-1; ++pos)
{
size_t left=pos-1;
size_t right=pos+1;
while((left<right && right<v.size()) && (v[left]==-1 copy[v[left]]==copy[v[right]]))
{
--left;
++right;
}
do
{
++left;
--right;
}
while(v[left]==-1);
if(left<right)
lst.push_back(str.substr(v[left], v[right]-v[left]+1));
}
return(lst.size()!=0);
}
void process(const std::string& str)
{
std::cout<<"Original:\t""<<str.c_str()<<"""<<std::endl;
std::string mod;
mod=str;
to_upper(mod);
std::cout<<"to_upper:\t""<<mod.c_str()<<"""<<std::endl;
mod=str;
to_lower(mod);
std::cout<<"to_lower:\t""<<mod.c_str()<<"""<<std::endl;
mod=str;
to_reverse(mod);
std::cout<<"to_reverse:\t""<<mod.c_str()<<"""<<std::endl;
mod=str;
to_ascending(mod);
std::cout<<"to_ascending:\t""<<mod.c_str()<<"""<<std::endl;
mod=str;
to_descending(mod);
std::cout<<"to_descending:\t""<<mod.c_str()<<"""<<std::endl;
mod=str;
std::list<std::string> lst;
if(palindromes(mod,lst))
for each(std::string str in lst)
std::cout<<"Palindrome:\t""<<str.c_str()<<"""<<std::endl;
else
std::cout<<"No palindromes were found!\n";
std::cout<<std::endl;
}
int main()
{
std::string str;
str = "The quick brown fox jumps over the lazy dog.";
process(str);
str = "Madam, I'm Adam.";
process(str);
str = "In girum imus nocte et consumimur igni.";
process(str);
}
Output:
Original: "The quick brown fox jumps over the lazy dog."
to_upper: "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG."
to_lower: "the quick brown fox jumps over the lazy dog."
to_reverse: ".god yzal eht revo spmuj xof nworb kciuq ehT"
to_ascending: " .Tabcdeeefghhijklmnoooopqrrstuuvwxyz"
to_descending: "zyxwvuutsrrqpoooonmlkjihhgfeeedcbaT. "
No palindromes were found!
Original: "Madam, I'm Adam."
to_upper: "MADAM, I'M ADAM."
to_lower: "madam, i'm adam."
to_reverse: ".madA m'I ,madaM"
to_ascending: " ',.AIMaaaddmmm"
to_descending: "mmmddaaaMIA.,' "
Palindrome: "Madam"
Palindrome: "Madam, I'm Adam"
Palindrome: "m Adam"
Original: "In girum imus nocte et consumimur igni."
to_upper: "IN GIRUM IMUS NOCTE ET CONSUMIMUR IGNI."
to_lower: "in girum imus nocte et consumimur igni."
to_reverse: ".ingi rumimusnoc te etcon sumi murig nI"
to_ascending: " .Icceeggiiiiimmmmnnnnoorrssttuuuu"
to_descending: "uuuuttssrroonnnnmmmmiiiiiggeeccI. "
Palindrome: "um imu"
Palindrome: "In girum imus nocte et consumimur igni"
Palindrome: "umimu"
The INT function is to convert something into an integer. An integer is a number that goes out two decimal places.
Prepare the string for processing: Remove all punctuation from the string (e.g., commas, hyphens, whitespace, etc). Convert to the same case (e.g., lower-case). Instantiate two pointers, one pointing at the first character, the other pointing at the last character. Process: If the two pointers are pointing at the same position or have crossed each other, the string is a palindrome. Otherwise, compare the characters being pointed at. If they are not equal, the string is not a palindrome. Otherwise, move both pointers one position towards the middle of the string and repeat the process.
/*To check whether a string is palindrome*/includeincludevoid main () {int i,j,f=0;char a[10];clrscr ();gets(a);for (i=0;a[i]!='\0';i++){}i--;for (j=0;a[j]!='\0';j++,i--){if (a[i]!=a[j])f=1;}if (f==0)printf("string is palindrome");else printf("string is not palindrome");getch ();}
jst subtract 32 from first character of string to convert it into capital
import java.io.*; public class chuva { public static void main(String[] args) throws Exception { BufferedReader x = new BufferedReader(new InputStreamReader(System.in)); int rem, quo, rev=0; System.out.println("Enter a number: "); int a = Integer.parseInt(x.readLine()); int b=a; for(int ctr=0; ctr<=a; ctr++) { rem = a%10; a = a/10; rev = rev*10 +rem; ctr=0; } System.out.println(+rev); if(b==rev) System.out.println("Palindrome"); else System.out.println("Not Palindrome"); } }
Listing the fractions is ascending (or descending) order.
Example 7, 30, 11, 27, 9, 16,Ascending Order = 7, 9, 11, 16, 27, 30 ( You simply arrange the number from lowest to highest number )Descending Order = 30, 27, 16, 11, 9, 7 ( You simply arrange the number from highest to lowest number )
To write fractions in order, first ensure they have a common denominator. If they don’t, find the least common denominator by identifying the smallest multiple shared by the denominators. Convert each fraction to an equivalent fraction with this common denominator, then compare the numerators to arrange them in ascending or descending order. Alternatively, you can convert fractions to decimals for easier comparison.
Convert them to common denominators and put the numerators in ascending order.
Find the lowest common denominator, convert them, and arrange them in ascending order.
To convert the number 449 into a palindrome using the reverse and add method, you would follow these steps: First, reverse 449 to get 944, then add the two numbers together (449 + 944 = 1393). Next, reverse 1393 to get 3931 and add them (1393 + 3931 = 5324). Finally, reverse 5324 to get 4235 and add them (5324 + 4235 = 9559), which is a palindrome. Thus, it takes a total of 3 steps to reach the palindrome 9559.
Its components
liver
investors can convert their shares by selling them to stock exchange
The date functions that exist in SQL are "NOW()", "CURDATE()", "CURTIME()", "DATE()", "EXTRACT()", "DATEDIFF()", "GETDATE()", "DATEPART()", and "CONVERT()".
It is to convert a function into a sum of sine (or cosine) functions so as to simplify its analysis.
Copy and reverse the string. If the reversed string is equal to the original string, the string is a palindrome, otherwise it is not. When working with strings that hold natural language phrases (including punctuation, whitespace and so on) we must remove all the non-alphanumerics and convert the remainder to a common case, such as lower-case, prior to copying and reversing the string.