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 parthapratimbanik Cpp14 0.00s
02 MAHRahat Cpp14 0.00s
03 7Mahfuz Cpp14 0.00s
04 emrul Cpp14 0.00s
05 afzalul Cpp14 0.00s
06 tarikul_4152 Cpp 0.00s
07 rayhan50001 Cpp 0.00s
08 Ziaul Cpp14 0.00s
09 Robbinb1993 Cpp14 0.00s
10 deloar1 Cpp 0.00s
11 nafischonchol Cpp 0.00s
12 Ehsanul_Fahad Cpp 0.00s
13 MRoy Cpp 0.00s
14 twyu0721 C 0.00s
15 feodorv Cpp 0.00s
16 mrinmoi Cpp 0.00s
17 SugiuraAyano Cpp 0.00s
18 neel71 Cpp 0.00s
19 iierrrorii Cpp 0.00s
20 wayne6172 C 0.00s
21 rashad1987 Cpp14 0.00s
22 Logic_Hunter Cpp14 0.00s
23 nazmul_bzs Cpp14 0.01s
24 Izanagi Cpp14 0.01s
25 khmahbub20 Cpp 0.01s
26 joymollick Cpp 0.01s
27 tariqiitju Cpp14 0.01s
28 moyeen Cpp 0.02s
29 RandyWaterhouse Python3 0.03s
30 rashedul007 CSharp 0.06s
31 mhmbd CSharp 0.07s
32 ImaginativeShohag Cpp14 0.22s
33 mahbub07 Cpp14 0.26s
34 RakibR3 Cpp14 0.28s
35 imran16 Cpp14 0.31s
36 moshiur_cse15 Cpp14 0.40s
37 njrafi Cpp14 0.50s
38 froghramar Cpp14 0.50s
39 Maroof Java 0.50s
40 rash29 Cpp14 0.58s
41 Dinar Java 0.59s
42 jalal CSharp 0.72s

Your feedback is our precious!

Or call +88 02 9853138 for support