DCP-7: Friendly URL Back to All Problems

Easy Beginners Problems > Ad-hoc


A friendly URL is a Web address that is easy to read and includes words that describe the content of the webpage. This type of URL can be "friendly" in two ways. 1) It can help visitors remember the Web address, and 2) it can help describe the page to search engines. To generate a friendly URL, we can take an approach that we take any contest and remove any character that is not suitable and replace them with dash. Also we need to limit it to a specific length so that it is not too long and lower case the letters. Afterwards we append this specific text to the base address of the website to create the full friendly URL. If we see an example, it can be easy to understand. For example, we want to create a friendly URL for coding contest 2. So we take the name of the contest which is: “Dev Skill Coding Contest – 2” and then we remove the spaces and large dash with normal dash character like this: “dev-skill-coding-contest-2”. As the length is short so we don’t have any problem. If the length was too long, then we should have taken only some character of the converted string. So now we can append this part with the base address like: **“https://www.devskill.com/newcontest/dev-skill-coding-contest-2”** and that is a nice friendly URL. For our problem we only need the converted text part and we do not need to append it with base URL, because if we can make the last part, adding with URL is no big issue. So the rules for this conversion will be as below: - Lower case all letters. - Replace all character except alphabet and digit with dash (‘-‘). Alphabets mean ‘A’ to ‘Z’ and ‘a’ to ‘z’ and digit means ‘0’ to ‘9’. - There can’t be two consecutive dashes. - There can’t be any leading and trailing dash. - New line character (‘\n’) is out of consideration as we consider it as our string ending character, but there can be tab character (‘\t’) which should also be considered invalid character and should be replaced. - The converted text should not be longer than the given maximum length. Input: ------ Input starts with an integer **T (≤ 30)**, denoting the number of test cases. The each **T** test cases next, there will be two lines – the first line contains the maximum length of the converted text and the second line contains the content text from which we have to create the friendly URL last part. The length of content text will be less than 1000 characters. There will be no blank line or any line without any valid character. Each line will at least have one alphabet or digit. The maximum length of the converted text will be a positive 32 bit integer. Output: ------- For each test case, print the converted friendly URL last part. Sample Input ------------ 3 26 Dev Skill Coding Contest 2 5 -a- 2 b b Sample Output ------------- dev-skill-coding-contest-2 a b


Problem Setter:

MD. Jalal Uddin

Please login to submit solution to this problem.

Problem Limits

Language Time Limit (seconds)
C/C++ 1.00
Java 3.00
C# 3.00
PHP 3.00

Problem Stats

24/94

Solve/Submission

Ranking

# User Language Timing
01 parthapratimbanik Cpp 0.00s
02 mahrahat Cpp 0.00s
03 7Mahfuz Cpp 0.00s
04 emrul Cpp 0.00s
05 tariqiitju Cpp 0.01s
06 mhmbd CSharp 0.07s
07 ImaginativeShohag Cpp 0.22s
08 mahbub07 Cpp 0.26s
09 RakibR3 Cpp 0.28s
10 imran16 Cpp 0.31s
11 moshiur_cse15 Cpp 0.40s
12 froghramar Cpp 0.50s
13 njrafi Cpp 0.50s
14 rash29 Cpp 0.58s
15 Dinar Java 0.59s
16 jalal CSharp 0.72s
17 mhsjaber CSharp 2.70s
Feedback

Your feedback is our precious!



Or call +88 02 9853138 for support