Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does C++ find the longest connection path of a string?

Shulou Source: shulou.com Published: 2022-06-01 19:30:32 10月03日 Update

This article mainly explains "how to find the longest connection path of a string in C++". The content in the article is simple and clear, and it is easy to learn and understand. Now please follow the editor's train of thought slowly and deeply. Let's study and learn how C++ finds the longest connection path for strings.

Topic description

Given n strings, please arrange the n strings in dictionary order.

Enter a description:

Enter a positive integer n (1 ≤ n ≤ 1000) for the first behavior, and the following n acts as n strings (string length ≤ 1000), which contains only uppercase and lowercase letters.

Output description:

The data output is n lines, and the output is a string arranged in dictionary order.

Example

Input

nine

Cap

To

Cat

Card

Two

Too

Up

Boat

Boot

Output

Boat

Boot

Cap

Card

Cat

To

Too

Two

Up

Analysis

To be honest, I didn't know this question would be called by that name on the Internet. Xiaobai thinks it should be called dictionary sorting. But it just so happens that the buddies can familiarize themselves with the associated container with Xiaobai. The data stored in the set association container itself is sorted in dictionary order, so we only need to input the data and read it sequentially to meet the requirements.

However, this question rookie encountered a problem during the test, that is, the pass rate was only 60%. Looking at the course of failure, it was found that there was a test data that contained two duplicate strings. So we need to use multiset to associate the container. This container allows duplicates of stored data and will save all of it, unlike the set container, which is saved only once. It's all in # include.

Code

# include

# include

# include

Using namespace std

Int main ()

{

Int index

While (cin > > index)

{

Multiset str_set

For (int itemositti > str)

Str_set.insert (str)

}

For (auto m:str_set)

Cout

Tags: Character string container data longest path clocked dictionary input output that is rookie association learning content situation result question order sort Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple OPPO Reno Docker Microsoft Huawei