• 练习一:单链表的反转,串的模式匹配


    #include "stdafx.h"
    #include "stdlib.h"
    #include<iostream>
    using namespace std;
    
    typedef struct node{
        int value;
        node * next;
    }* LNode ;
    
    int main(int argc, char* argv[])
    {
        LNode Inputlist();
        void OutPutList(const LNode head);
        LNode Converse(LNode head);
        LNode head =Inputlist();
        OutPutList(head);
        head = Converse(head);
        OutPutList(head);
        free(head);
        return 0;
    }
    //链表的反转
    LNode Converse(LNode head)
    {
        LNode A,B,C;
        A=head;
        B=head->next;
        C=head->next->next;
        head->next=NULL;
        while (C!=NULL)
        {
            B->next=A;
            A=B;
            B=C;
            C=C->next;
        }
        B->next=A;
        head =B;
        return head;
    }
    //链表输入 输入11结束链表
    LNode Inputlist()
    {
        LNode head,p;
        head =(LNode)malloc(sizeof(node));
        int a;
        cin>>a;
        if(a!=11)
        {
            head->value=a;
            p=head;
        }
        else
        {
            head=NULL;
            return head;
        }
        cin>>a;
        while (a!=11)
        {        
            p->next =(LNode)malloc(sizeof(node));
            p->next->value=a;
            p=p->next;
            cin>>a;
        }  
        p->next=NULL;
        return head;
    }
    
    //链表输出
    void OutPutList(const LNode head)
    {
        LNode p;
        p=head;
        while(p->next!=NULL)
        {
            cout<<p->value<<"->";
            p=p->next;
        }
        cout<<p->value<<endl;
    }
    //输入ad   sd d  输出ad,sd,d,
    void DivideString(const char *pInputStr, long lInputLen, char *pOutputStr)
    {
        long j = 0;  
        for(long i=0;pInputStr[i]!='';i++) 
        {   
            if(pInputStr[i]!=32) 
            {       
                pOutputStr[j]= pInputStr[i];   
                j++;   
            } 
            
            else {    
                if(pOutputStr[j-1] != ',')  
                {  
                    pOutputStr[j]=',';   
                    j++;   
                } 
            }
        }
        pOutputStr[j]=',';   
        pOutputStr[j+1]='';  
    }
    
    //串的模式匹配
    int StrIndex_BF(char *s,char *t)
    {
        int i=1,j=1;
        while (s[i]!='' && t[j]!='')
        {
            if(s[i]==t[j])
            {
                i++;
                j++;
            }
            else
            {
                i=i-j+2;
                j=1;
            }            
        }
        if(t[j]=='')
            return i-j;
        else return 0;    
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    int fn( int n)
    {
        if(n==1 || n==2)
            return 1;
        return fn(n-1)+2*fn(n-2);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    //求和  只含1 和 7 的自然数
    int  fuc()
    {
        int k=0,j=0,m=0;
        bool s=true;
        for(int i=0;i<3000;i++)
        {
            j=i;s=true;
            while(j>0)
            {
                k=j%10;
                if(k==7 || k==1)
                {
                    j=j/10;
                }
                else
                {
                    s=false;
                    break;
                }
            }
            if(s)
            {
                m=m+i;
            }
            
        }
        return m;
    }
  • 相关阅读:
    php单点登录
    【Docker】docker镜像构建
    【测试经验】网关中间件测试
    【Jmeter】调用Dubbo方法
    【计算机网络】TCP三次握手与四次挥手
    【操作系统】死锁
    【操作系统】线程与进程
    【计算机网络】TCP/IP
    【计算机网络】Http与Https
    【二叉树】二叉树的创建与遍历
  • 原文地址:https://www.cnblogs.com/ymecho/p/3327160.html
Copyright © 2020-2023  润新知