Get the App
SLTechnology News&Howtos  ›  Development  › 

How does C language output the only substring

Shulou Source: shulou.com Published: 2022-06-02 07:27:05 10月19日 Update

How does C language output the only substring? in order to solve this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a simpler and easier way.

Topic description

Give a string and find all non-repeating substrings of length m. For example, if the string "aaab" is a substring of length 2, then it is "aa", "aa" and "ab" in turn, and the non-repetitive substrings are "aa" and "ab".

Input

The first line is an integer K, which represents the number of samples. The first line of each sample is an integer m, which represents the length of the requested substring. The second line is a string that consists entirely of lowercase letters and is no more than 100 in length.

Output

Output all unrepeated substrings in lexicographical order, with each sample finally outputting a blank line.

Sample input

two

two

Aaab

three

Aaab

Sample output

Aa

Ab

Aaa

This problem can define a two-dimensional array to hold all the substrings of the string, then sort it, and finally output one by one, only one of the same.

The complete code # include # include int main () {int kjjjjjjjjjjjpjlpjlpjlpjlpjlpl; char str [105a] = {0}, a [102l] [101l] = {0}, temp [100]; scanf ("% d", & k); while (Kmurf -) {n = 0; scanf ("% d", & m); scanf ("% s", str); len = strlen (str) For (I = 0 I 0) {strcpy (temp,a [I]); strcpy (a [I], a [j]); strcpy (a [j], temp);} for (I = 0 X I < n I if +) {if (strcmp (a [I], a [I + 1]) = 0) / / the same output only the first continue; for (j = 0 * j < m * * j +) printf ("% c", a [I] [j]); printf ("\ n");} printf ("\ n") Memset (str,'\ 0recording journal sizeof (str)); memset (a recorder'\ 0recording recording sizeof (a)); memset (temp,'\ 0recording journal sizeof (temp));} return 0 } the answer to the question about how the C language outputs the only substring is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Tags: Output character string length question language same one line integer more help sort answer input easy easy number code content dictionary Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Tech Info NVidia Docker macOS