Last active
December 11, 2015 19:28
-
-
Save tuankiet65/4648716 to your computer and use it in GitHub Desktop.
Facebook Hacker Cup 2013 - Beautiful Strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 | |
ABbCcc | |
Good luck in the Facebook Hacker Cup this year! | |
Ignore punctuation, please :) | |
Sometimes test cases are hard to make up. | |
So I just go consult Professor Dalves |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Case #1: 152 | |
Case #2: 754 | |
Case #3: 491 | |
Case #4: 729 | |
Case #5: 646 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rogram facebook1; | |
uses crt; | |
var t, t2: text; | |
sarray: array [1..100000] of widestring; | |
a: array [65..90] of longint; | |
tc, chk, i2, i, i4, i5, tg: longint; | |
ts, wkst: widestring; | |
tong: int64; | |
begin | |
clrscr; | |
{======================================================================} | |
tc:=0; | |
chk:=0; | |
{======================================================================} | |
assign(t, 'inp.txt'); | |
reset(t); | |
{======================================================================} | |
readln(t, ts); | |
val(ts, tc, chk); | |
{======================================================================} | |
for i:=1 to tc do readln(t, sarray[i]); | |
close(t); | |
{======================================================================} | |
fillchar(a, sizeof(a), 0); | |
{======================================================================} | |
assign(t2, 'out.txt'); | |
rewrite(t2); | |
{======================================================================} | |
for i:=1 to tc do begin | |
wkst:=sarray[i]; | |
{======================================================================} | |
for i2:=1 to length(sarray[i]) do begin | |
if (ord(upcase(wkst[i2]))>=65) and (ord(upcase(wkst[i2]))<=90) then begin | |
inc(a[ord(upcase(wkst[i2]))]); | |
end; | |
end; | |
{======================================================================} | |
for i4:=65 to 89 do | |
for i5:=i4+1 to 90 do | |
if (a[i4]<a[i5]) then begin | |
tg:=a[i4]; | |
a[i4]:=a[i5]; | |
a[i5]:=tg; | |
end; | |
{======================================================================} | |
i5:=26; | |
for i4:=65 to 89 do begin | |
a[i4]:=i5*a[i4]; | |
i5:=i5-1; | |
end; | |
{======================================================================} | |
for i4:=65 to 90 do tong:=tong+a[i4]; | |
writeln(t2, 'Case #', i, ': ', tong); | |
tong:=0; | |
fillchar(a, sizeof(a), 0); | |
end; | |
close(t2); | |
writeln('Success!'); | |
readln; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment