C++ Code Check Whether The String Contains Adjacent Charecters Or Not


C++  Code Check  Whether The String   Contains Adjacent Charecters Or Not  :
============================================================


#include <iostream>
#include <string>
using namespace std;
int main()
{

    int any;
    cout<<"*********  ADJACENT CHARECTER IN THE STRING ************"<<endl;
    cout<<"\nEnter 1 to Preceed or 0 to exit : "<<endl;
    cin>>any;
    if(any!=0)
    {
        do
        {
            string any1,temp1,temp2;
            int y=0;
            cout<<"\nEnter the string : ";
            cin>>any1;
            for(int x=any1.length()-1; x>0; --x)
            {
                temp1=any1.substr(x,1);
                temp2=any1.substr(x-1,1);
                if(temp1==temp2)
                {
                    ++y;
                }
            }
            if (y!=0)
            {
cout<<"\nThe String Contains Adjacent Charecter."<<endl;

}
            else
            {

                cout<<"\nThe String does not contains Adjacent Charecter."<<endl;
            }
            cout<<"\n======================================"<<endl;
            cout<<"\nEnter 1 to Preceed or 0 to exit : "<<endl;
            cin>>any;
        }
        while(any!=0);
    }
}

No comments:

Post a Comment