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}