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 mrinmoi Cpp 0.00s
07 feodorv Cpp 0.00s
08 Ehsanul_Fahad Cpp 0.00s
09 MRoy Cpp 0.00s
10 twyu0721 C 0.00s
11 tarikul_4152 Cpp 0.00s
12 wayne6172 C 0.00s
13 rayhan50001 Cpp 0.00s
14 Ziaul Cpp14 0.00s
15 Robbinb1993 Cpp14 0.00s
16 deloar1 Cpp 0.00s
17 nafischonchol Cpp 0.00s
18 SugiuraAyano Cpp 0.00s
19 neel71 Cpp 0.00s
20 iierrrorii Cpp 0.00s
21 rashad1987 Cpp14 0.00s
22 Logic_Hunter Cpp14 0.00s
23 khmahbub20 Cpp 0.01s
24 tariqiitju Cpp14 0.01s
25 Izanagi Cpp14 0.01s
26 Yeasin10A Cpp 0.01s
27 rashidlkk Cpp 0.01s
28 joymollick Cpp 0.01s
29 nazmul_bzs Cpp14 0.01s
30 samir143009 CSharp 0.02s
31 aust_anik CSharp 0.02s
32 hossaintanbir0 CSharp 0.02s
33 armanabdullah CSharp 0.02s
34 ICT_backbencher CSharp 0.02s
35 moyeen Cpp 0.02s
36 Taj025 CSharp 0.02s
37 Atm_Ahad CSharp 0.03s
38 RandyWaterhouse Python3 0.03s
39 lazyfahim CSharp 0.03s
40 fahimali CSharp 0.03s
41 Maaaruf CSharp 0.03s
42 noyonhossen CSharp 0.03s
43 rashedul007 CSharp 0.06s
44 mhmbd CSharp 0.07s
45 kazimoin CSharp 0.07s
46 ImaginativeShohag Cpp14 0.22s
47 mahbub07 Cpp14 0.26s
48 RakibR3 Cpp14 0.28s
49 imran16 Cpp14 0.31s
50 moshiur_cse15 Cpp14 0.40s

Your feedback is our precious!

Or call +88 02 9853138 for support