C ++ Programming Practice Guide 1.15 find out the implementation of the rewriting requirements of the number of input files, and program design practice 1.15

Source: Internet
Author: User

C ++ Programming Practice Guide 1.15 find out the implementation of the rewriting requirements of the number of input files, and program design practice 1.15

Rewrite requirement 1: using a single-chain table

#include <cstdlib>#include <iostream>using namespace std;struct LinkNode{       int data;       LinkNode *next;};class PALINDROME{      int low,up;      int a[100];      int count;      public:             PALINDROME(int t1,int t2);             int IsPalin(int x);             LinkNode* IsPalinAndStore();             void OutputResults(LinkNode* Head);};PALINDROME::PALINDROME(int t1,int t2){   count=0;   low=t1;   up=t2;}LinkNode* PALINDROME::IsPalinAndStore(){     LinkNode* Head=new LinkNode;     Head->next=NULL;     LinkNode* p=Head;     for(int i=low;i<=up;i++)     {             int x=i*i;             if(IsPalin(x))             {                LinkNode* newLinkNode=new LinkNode;                newLinkNode->next=NULL;                newLinkNode->data=i;                p->next=newLinkNode;                p=newLinkNode;             }     }     return Head;}void PALINDROME::OutputResults(LinkNode* Head){     LinkNode* p=Head->next;     cout<<"count="<<count<<endl;     cout<<"x"<<'\t'<<"x*x"<<endl;     while(p)     {        cout<<p->data<<'\t'<<p->data*p->data<<endl;        p=p->next;     }}int PALINDROME::IsPalin(int x){    int i=0,j,n;    int a[100];    while(x)    {       a[i]=x%10;       x=x/10;       i++;    }    n=i;    for(i=0,j=n-1;i<=j;i++,j--)       if(a[i]!=a[j])          return 0;       return 1;}int main(int argc, char *argv[]){    LinkNode* Head=new LinkNode;    PALINDROME p(100,1000);    Head=p.IsPalinAndStore();    p.OutputResults(Head);    system("PAUSE");    return EXIT_SUCCESS;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.