码迷,mamicode.com
首页 > 其他好文 > 详细

重温考研真题...

时间:2016-04-01 01:01:27      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

#include <stdio.h>

struct node{
        char data;
        struct node *next;
} NODE;


struct node *find(struct node *str1, struct node *str2){
        int str1_len = 0, str2_len = 0;
        struct node *p = str1;
        while(p->next != NULL){
                str1_len++;
                p = p->next;
        }
        p = str2;
        while(p->next != NULL){
                str2_len++;
                p = p->next;
        }

        int i, tmp;
        if(str1_len > str2_len){
                tmp = str1_len - str2_len;
                for(i=0; i<tmp; i++){
                        str1 = str1->next;
                }
        }else{
                tmp = str2_len - str1_len;
                for(i=0; i<tmp; i++){
                        str2 = str2->next;
                }
        }

        p = NULL;
        while(str1 != NULL){
                if(str1->data == str2->data){
                        if(p == NULL){
                                p = str1;
                        }
                }else{
                        p = NULL;
                }
                str1 = str1->next;
                str2 = str2->next;
        }

        return p;
}

 

重温考研真题...

标签:

原文地址:http://www.cnblogs.com/bai-jimmy/p/5343481.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!