blob: 520282b4cf760a3e7d477292a7688578f1ca1ede (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
Task 1: "Common Base String
You are given 2 strings, $A and $B.
Write a script to find out common base strings in $A and $B.
A substring of a string $S is called base string if repeated concatenation
of the substring results in the string.
Example 1:
Input:
$A = "abcdabcd"
$B = "abcdabcdabcdabcd"
Output:
("abcd", "abcdabcd")
Example 2:
Input:
$A = "aaa"
$B = "aa"
Output:
("a")"
My notes: ok. interesting. sounds like a job for regex matching
Task 2: "Frequency Sort
You are given file named input.
Write a script to find the frequency of all the words.
It should print the result as first column of each line should be the
frequency of the the word followed by all the words of that frequency
arranged in lexicographical order. Also sort the words in the ascending
order of frequency.
INPUT file
West Side Story
The award-winning adaptation of the classic romantic tragedy "Romeo and
Juliet". The feuding families become two warring New York City gangs,
the white Jets led by Riff and the Latino Sharks, led by Bernardo. Their
hatred escalates to a point where neither can coexist with any form
of understanding. But when Riff's best friend (and former Jet) Tony
and Bernardo's younger sister Maria meet at a dance, no one can do
anything to stop their love. Maria and Tony begin meeting in secret,
planning to run away. Then the Sharks and Jets plan a rumble under the
highway--whoever wins gains control of the streets. Maria sends Tony
to stop it, hoping it can end the violence. It goes terribly wrong,
and before the lovers know what's happened, tragedy strikes and doesn't
stop until the climactic and heartbreaking ending.
NOTE
For the sake of this task, please ignore the following in the input file:
. " ( ) , 's --
OUTPUT
1 But City It Jet Juliet Latino New Romeo Side Story Their Then West York
adaptation any anything at award-winning away become before begin best
classic climactic coexist control dance do doesn't end ending escalates
families feuding form former friend gains gangs goes happened hatred
heartbreaking highway hoping in know love lovers meet meeting neither no
one plan planning point romantic rumble run secret sends sister streets
strikes terribly their two under understanding until violence warring
what when where white whoever wins with wrong younger
2 Bernardo Jets Riff Sharks The by it led tragedy
3 Maria Tony a can of stop
4 to
9 and the
"
My notes: classic. data structure is freq -> list of words of that frequency.
|