Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does C language output the only substring

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report