File tree Expand file tree Collapse file tree 4 files changed +75
-0
lines changed Expand file tree Collapse file tree 4 files changed +75
-0
lines changed Original file line number Diff line number Diff line change
1
+ # !/usr/bin/perl
2
+
3
+ use strict;
4
+ use warnings;
5
+
6
+ # Read sentence from standard input
7
+ print (" Enter the sentence:\n " );
8
+ chomp (my $str = <STDIN >);
9
+
10
+ # Read broken keys as space-separated input from standard input
11
+ print (" Enter the broken keys as space-separated:\n " );
12
+ chomp (my $keys_line = <STDIN >);
13
+ my @keys = split /\s +/, $keys_line ;
14
+
15
+ my %broken = map { lc ($_ ) => 1 } @keys ;
16
+ my @words = split /\s +/, $str ;
17
+
18
+ my $count = 0;
19
+ foreach my $word (@words ) {
20
+ my $can_type = 1;
21
+ foreach my $char (split //, lc ($word )) {
22
+ if ($broken {$char }) {
23
+ $can_type = 0;
24
+ last ;
25
+ }
26
+ }
27
+ $count ++ if $can_type ;
28
+ }
29
+
30
+ print " $count \n " ;
Original file line number Diff line number Diff line change
1
+ # !/usr/bin/perl
2
+
3
+ use strict;
4
+ use warnings;
5
+
6
+ print " Enter the string: " ;
7
+ chomp (my $str = <STDIN >);
8
+
9
+ print " Enter the character to reverse prefix until: " ;
10
+ chomp (my $char = <STDIN >);
11
+
12
+ my $index = index ($str , $char );
13
+
14
+ if ($index == -1 || $index == 0) {
15
+ print " $str \n " ;
16
+ } else {
17
+ my $prefix = substr ($str , 0, $index + 1);
18
+ my $reversed = reverse $prefix ;
19
+ print $reversed . substr ($str , $index + 1) . " \n " ;
20
+ }
Original file line number Diff line number Diff line change
1
+ sentence = input ("Enter the sentence: " )
2
+ keys_input = input ("Enter the broken keys separated by space: " )
3
+
4
+ broken_keys = set (keys_input .lower ().split ())
5
+
6
+ count = 0
7
+ for word in sentence .split ():
8
+ if all (char not in broken_keys for char in word .lower ()):
9
+ count += 1
10
+
11
+ print (f"Number of words that can be typed: { count } " )
Original file line number Diff line number Diff line change
1
+ input_str = input ("Enter the string: " )
2
+ char = input ("Enter the character to reverse prefix until: " )
3
+
4
+ index = input_str .find (char )
5
+
6
+ if index == - 1 or index == 0 :
7
+ # No change if character not found or at start
8
+ result = input_str
9
+ else :
10
+ prefix = input_str [:index + 1 ]
11
+ rest = input_str [index + 1 :]
12
+ result = prefix [::- 1 ] + rest
13
+
14
+ print (f"Resulting string: { result } " )
You can’t perform that action at this time.
0 commit comments