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 1.00
C++ 1.00
C++14 1.00
C# 3.00
Go 3.00
Java 3.00
JavaScript 3.00
Objective-C 3.00
Perl 3.00
PHP 3.00
Python 3.00
Python3 3.00
Ruby 3.00
VB.Net 3.00

Problem Stats




# User Language Timing
01 MAHRahat Cpp14 0.00s
02 emrul Cpp14 0.00s
03 7Mahfuz Cpp14 0.00s
04 afzalul Cpp14 0.00s
05 mrinmoi Cpp 0.00s
06 parthapratimbanik Cpp14 0.00s
07 feodorv Cpp 0.00s
08 Ehsanul_Fahad Cpp 0.00s
09 tariqiitju Cpp14 0.01s
10 khmahbub20 Cpp 0.01s
11 nazmul_bzs Cpp14 0.01s
12 RandyWaterhouse Python3 0.03s
13 rashedul007 CSharp 0.06s
14 mhsjaber CSharp 0.06s
15 mhmbd CSharp 0.07s
16 ImaginativeShohag Cpp14 0.22s
17 mahbub07 Cpp14 0.26s
18 RakibR3 Cpp14 0.28s
19 imran16 Cpp14 0.31s
20 moshiur_cse15 Cpp14 0.40s
21 froghramar Cpp14 0.50s
22 njrafi Cpp14 0.50s
23 Maroof Java 0.50s
24 rash29 Cpp14 0.58s
25 Dinar Java 0.59s
26 jalal CSharp 0.72s

Your feedback is our precious!

Or call +88 02 9853138 for support