aboutsummaryrefslogtreecommitdiff
path: root/challenge-060/plis-acm/perl/ch-1.pl
blob: fd7ae5a34acc66b4b06e407170b2628b53c92a2c (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
#!/usr/bin/env perl

use 5.018;
use utf8;
use warnings;
use diagnostics;

print "Input Number: ";
chomp(my $input = <STDIN>);
if ($input eq "") {
    print "empty input";
} else {
    my $res;
    if ($input =~ /\d+/) {
        $res = "A" x ($input / 26);
        $res .= chr($input % 26 - 1 + ord('A'));
    } else {
        for (split '', $input) {
            if ($_ eq 'A') { $res += 26; }
            else { $res += (ord($_) - ord('A') + 1); }
        }
    }
    print "Output: $res\n";
}