Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Perl
Checking the sample code
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
use strict;
use warnings;
use 5.20.1;
select(STDOUT); $| = 1; # DO NOT REMOVE
#chomp(my $m = <STDIN>);
my $m = "CG";
my @mc = split("", $m);
my %c = (
"0", "00",
"1", "0"
);
my $b = "";
for my $i (0..(length($m) - 1)) {
$b .= sprintf("%07b", ord($mc[$i]));
}
my @bc = split("", $b);
my $ans = $c{$bc[0]} . " 0";
for my $i (1..(length($b) - 1)) {
if ($bc[$i] == $bc[$i - 1]) {
$ans .= "0";
} else {
$ans .= " " . $c{$bc[$i]} . " 0";
}
}
# To debug: print STDERR "Debug messages...\n";
print $ans . "\n";
Enter to Rename, Shift+Enter to Preview
Looking at the syntax
- TODO
Other characteristics
- TODO
Resources to check
Coming next...
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content