C language determines whether a sequence is another sub-sequence, and C language sequence is another

Source: Internet
Author: User

C language determines whether a sequence is another sub-sequence, and C language sequence is another

1 # include <stdio. h> 2 # include <string. h> // Add the string header file 3 4 int Subsequence (char s [], char t []) 5 {6 int m, n, I, j; 7 n = strlen (s); // n indicates the length of the sequence S 8 m = strlen (t); // m indicates the length of the sequence T 9 I = 0; 10 j = 0; 11 if (m> n) 12 return 0; // T is not the child sequence of S 13 while (I <m) & (j <n )) 14 {15 if (t [I] = s [j]) 16 // element I in sequence T is equal to element j in sequence S 17 I = I + 1; 18 j = j + 1; 19} 20 if (strstr (s, t )! = NULL) 21 return 1; // T is the Child sequence of S 22 return 0; 23} 24 25 26 int main () 27 {28 int Subsequence (char s [], char t []); 29 char s [30], t [30]; 30 int n, m; 31 32 printf ("*********************************** * ************** \ n "); 33 printf ("suborder column determination Calculation Method \ n "); 34 printf ("************************************ * ************* \ n "); 35 36 printf ("in which sequence Do You Want To determine? Please input (1 ~ 100): "); 37 scanf (" % d ", & n); 38 printf (" \ n "); 39 40 m = 1; 41 while (n --) 42 {43 44 printf ("Enter the % d sequence to be matched in group S:", m); 45 scanf ("% s", s ); 46 printf ("Enter the % d sequence to be matched in group T:", m); 47 scanf ("% s", t); 48 if (Subsequence (s, t) 49 printf ("sequence T (% s) is a subsequence of the series S (% s. \ N ", t, s); 50 else 51 printf (" sequence T (% s) is not a subsequence of sequence S (% s. \ N ", t, s); 52 m ++; 53} 54}

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.