Currency exchange rate

STDIN contains the exchange rate of 1 USD against other currencies.
STDOUT should contain a cross-table relationships each currency for each.

The columns should be sorted the same way as in the original list, table cells should be separated by two spaces.

IN

1 USD
0.82 EUR
1.23 AUD
0.99 CHF
1.32 SGD
52.03 RUB

OUT

\    USD   EUR   AUD   CHF   SGD   RUB
USD  1     0.82  1.23  0.99  1.32  52.03
EUR  1.22  1     1.50  1.21  1.61  63.45
AUD  0.81  0.67  1     0.80  1.07  42.30
CHF  1.01  0.83  1.24  1     1.33  52.56
SGD  0.76  0.62  0.93  0.75  1     39.42
RUB  0.02  0.02  0.02  0.02  0.03  1

IN

1 USD
0.82 EUR

OUT

\    USD   EUR
USD  1     0.82
EUR  1.22  1

IN

1 USD

OUT

\    USD
USD  1
Login to submit solution


205 symbols python2 failed test 1 Wrong answer
\    USD   EUR   AUD   CHF   SGD   RUB
USD  1     0.82  1.23  0.99  1.32  52.03
EUR  1.22  1     1.50  1.21  1.61  63.45
AUD  0.81  0.67  1     0.80  1.07  42.30
CHF  1.01  0.83  1.24  1     1.33  52.56
SGD  0.76  0.62  0.93  0.75  1     39.42
RUB  0.02  0.02  0.02  0.02  0.03  1   
instead of
\    USD   EUR   AUD   CHF   SGD   RUB
USD  1     0.82  1.23  0.99  1.32  52.03
EUR  1.22  1     1.50  1.21  1.61  63.45
AUD  0.81  0.67  1     0.80  1.07  42.30
CHF  1.01  0.83  1.24  1     1.33  52.56
SGD  0.76  0.62  0.93  0.75  1     39.42
RUB  0.02  0.02  0.02  0.02  0.03  1
Mon Dec 29 17:18:41 2014 PFischbeck
import sys
c=[]
d=[]
for s in sys.stdin:
 [a,b]=s.split()
 d+=[float(a)]
 c+=[b]
print"\\    "+"   ".join(c)
l=range(len(c))
for i in l:print"  ".join([c[i]]+[("%.2f"%(d[j]/d[i]),"1   ")[i==j] for j in l])
184 symbols perl failed test 2 Wrong answer
\    USD   EUR
USD  1     0.82 
EUR  1.22  1
instead of
\    USD   EUR
USD  1     0.82
EUR  1.22  1
Mon Dec 29 19:58:17 2014 danieljabailey
sub p{print@_}for(<>){s/(\D{3})$//;push@c,$1;$m{$1}=$_}p"\\ ";for(@c){p"   ",$_}p$/;for(@c){p$_," ";$v=$_;for(@c){($v eq$_)?p$c[-1]ne$v?" 1    ":" 1":printf" %-5.2f",$m{$_}/$m{$v}}p$/}
161 symbols perl failed test 1 Wrong answer
/    USD   EUR   AUD   CHF   SGD   RUB
USD  1     0.82  1.23  0.99  1.32  52.03
EUR  1.22  1     1.50  1.21  1.61  63.45
AUD  0.81  0.67  1     0.80  1.07  42.30
CHF  1.01  0.83  1.24  1     1.33  52.56
SGD  0.76  0.62  0.93  0.75  1     39.42
RUB  0.02  0.02  0.02  0.02  0.03  1   
instead of
\    USD   EUR   AUD   CHF   SGD   RUB
USD  1     0.82  1.23  0.99  1.32  52.03
EUR  1.22  1     1.50  1.21  1.61  63.45
AUD  0.81  0.67  1     0.80  1.07  42.30
CHF  1.01  0.83  1.24  1     1.33  52.56
SGD  0.76  0.62  0.93  0.75  1     39.42
RUB  0.02  0.02  0.02  0.02  0.03  1
Sun Jan 4 01:31:55 2015 vakorol
#!/usr/bin/perl -ap
/\S+$/;$s||="/ ";push@n,$&;push@v,$`;$s.="   $&"}{$s.="\n";$s.=$n[$i],(map{$s.=sprintf$_==$v[$i]?"  %-4i":"  %.2f",$_/$v[$i]}@v),$s.="\n",$i++while$i<@n;$_=$s
162 symbols perl failed test 1 Wrong answer
\    USD   EUR   AUD   CHF   SGD   RUB
USD  1     0.82  1.23  0.99  1.32  52.03
EUR  1.22  1     1.50  1.21  1.61  63.45
AUD  0.81  0.67  1     0.80  1.07  42.30
CHF  1.01  0.83  1.24  1     1.33  52.56
SGD  0.76  0.62  0.93  0.75  1     39.42
RUB  0.02  0.02  0.02  0.02  0.03  1   
instead of
\    USD   EUR   AUD   CHF   SGD   RUB
USD  1     0.82  1.23  0.99  1.32  52.03
EUR  1.22  1     1.50  1.21  1.61  63.45
AUD  0.81  0.67  1     0.80  1.07  42.30
CHF  1.01  0.83  1.24  1     1.33  52.56
SGD  0.76  0.62  0.93  0.75  1     39.42
RUB  0.02  0.02  0.02  0.02  0.03  1
Sun Jan 4 01:32:45 2015 vakorol
#!/usr/bin/perl -ap
/\S+$/;$s||="\\ ";push@n,$&;push@v,$`;$s.="   $&"}{$s.="\n";$s.=$n[$i],(map{$s.=sprintf$_==$v[$i]?"  %-4i":"  %.2f",$_/$v[$i]}@v),$s.="\n",$i++while$i<@n;$_=$s
247 symbols haskell failed test 1 Wrong answer
\     USD   EUR   AUD   CHF   SGD   RU
USD   1      0.82   1.23   0.99   1.32   52.03
EUR   1.22   1      1.50   1.21   1.61   63.45
AUD   0.81   0.67   1      0.80   1.07   42.30
CHF   1.01   0.83   1.24   1      1.33   52.56
SGD   0.76   0.62   0.93   0.75   1      39.42
RUB   0.02   0.02   0.02   0.02   0.03   1   
instead of
\    USD   EUR   AUD   CHF   SGD   RUB
USD  1     0.82  1.23  0.99  1.32  52.03
EUR  1.22  1     1.50  1.21  1.61  63.45
AUD  0.81  0.67  1     0.80  1.07  42.30
CHF  1.01  0.83  1.24  1     1.33  52.56
SGD  0.76  0.62  0.93  0.75  1     39.42
RUB  0.02  0.02  0.02  0.02  0.03  1
Sun Mar 15 12:21:56 2015 YoshikuniJujo
import Numeric
t=init
m=map
main=interact$unlines.(\(x:s)->t x:s).m(t.t.unwords).w.m((\[r,n]->(read r,n)).words).lines
w r=("\\    ":n):zipWith(:)n(m(m i)$m((\x->m((/x).fst)r).fst)r)where n=m((++"  ").snd)r
i 1="1     "
i x=showFFloat(Just 2)x"  "
249 symbols haskell failed test 1 Wrong answer
\      USD    EUR    AUD    CHF    SGD    RUB
USD    1      0.82   1.23   0.99   1.32   52.03
EUR    1.22   1      1.50   1.21   1.61   63.45
AUD    0.81   0.67   1      0.80   1.07   42.30
CHF    1.01   0.83   1.24   1      1.33   52.56
SGD    0.76   0.62   0.93   0.75   1      39.42
RUB    0.02   0.02   0.02   0.02   0.03   1   
instead of
\    USD   EUR   AUD   CHF   SGD   RUB
USD  1     0.82  1.23  0.99  1.32  52.03
EUR  1.22  1     1.50  1.21  1.61  63.45
AUD  0.81  0.67  1     0.80  1.07  42.30
CHF  1.01  0.83  1.24  1     1.33  52.56
SGD  0.76  0.62  0.93  0.75  1     39.42
RUB  0.02  0.02  0.02  0.02  0.03  1
Sun Mar 15 12:24:01 2015 YoshikuniJujo
import Numeric
t=init
m=map
main=interact$unlines.(\(x:s)->t x:s).m(t.t.unwords).w.m((\[r,n]->(read r,n)).words).lines
w r=("\\     ":n):zipWith(:)n(m(m i)$m((\x->m((/x).fst)r).fst)r)where n=m((++"   ").snd)r
i 1="1     "
i x=showFFloat(Just 2)x"  "
255 symbols haskell failed test 1 Wrong answer
\    USD    EUR    AUD    CHF    SGD    RUB
USD  1      0.82   1.23   0.99   1.32   52.03
EUR  1.22   1      1.50   1.21   1.61   63.45
AUD  0.81   0.67   1      0.80   1.07   42.30
CHF  1.01   0.83   1.24   1      1.33   52.56
SGD  0.76   0.62   0.93   0.75   1      39.42
RUB  0.02   0.02   0.02   0.02   0.03   1   
instead of
\    USD   EUR   AUD   CHF   SGD   RUB
USD  1     0.82  1.23  0.99  1.32  52.03
EUR  1.22  1     1.50  1.21  1.61  63.45
AUD  0.81  0.67  1     0.80  1.07  42.30
CHF  1.01  0.83  1.24  1     1.33  52.56
SGD  0.76  0.62  0.93  0.75  1     39.42
RUB  0.02  0.02  0.02  0.02  0.03  1
Sun Mar 15 12:31:38 2015 YoshikuniJujo
import Numeric
t=init
m=map
main=interact$unlines.(\(x:s)->t x:s).m(t.t.unwords).w.m((\[r,n]->(read r,n)).words).lines
w r=("\\   ":n):zipWith(:)(m(t.t)n)(m(m i)$m((\x->m((/x).fst)r).fst)r)where n=m((++"   ").snd)r
i 1="1     "
i x=showFFloat(Just 2)x"  "
234 symbols haskell failed test 1 Wrong answer
\    USD   EUR   AUD   CHF   SGD   RUB
USD  1     0.82  1.23  0.99  1.32  52.0
EUR  1.22  1     1.50  1.21  1.61  63.4
AUD  0.81  0.67  1     0.80  1.07  42.3
CHF  1.01  0.83  1.24  1     1.33  52.5
SGD  0.76  0.62  0.93  0.75  1     39.4
RUB  0.02  0.02  0.02  0.02  0.03  1  
instead of
\    USD   EUR   AUD   CHF   SGD   RUB
USD  1     0.82  1.23  0.99  1.32  52.03
EUR  1.22  1     1.50  1.21  1.61  63.45
AUD  0.81  0.67  1     0.80  1.07  42.30
CHF  1.01  0.83  1.24  1     1.33  52.56
SGD  0.76  0.62  0.93  0.75  1     39.42
RUB  0.02  0.02  0.02  0.02  0.03  1
Sun Mar 15 12:35:20 2015 YoshikuniJujo
import Numeric
t=init
m=map
main=interact$unlines.m(t.t.unwords).w.m((\[r,n]->(read r,n)).words).lines
w r=("\\   ":n):zipWith(:)(m t n)(m(m i)$m((\x->m((/x).fst)r).fst)r)where n=m((++"  ").snd)r
i 1="1    "
i x=showFFloat(Just 2)x" "
248 symbols haskell failed test 1 Wrong answer
\    USD   EUR   AUD   CHF   SGD   RUB
USD  1     0.82  1.23  0.99  1.32  52.03
EUR  1.22  1     1.50  1.21  1.61  63.45
AUD  0.81  0.67  1     0.80  1.07  42.30
CHF  1.01  0.83  1.24  1     1.33  52.56
SGD  0.76  0.62  0.93  0.75  1     39.42
RUB  0.02  0.02  0.02  0.02  0.03  1   
instead of
\    USD   EUR   AUD   CHF   SGD   RUB
USD  1     0.82  1.23  0.99  1.32  52.03
EUR  1.22  1     1.50  1.21  1.61  63.45
AUD  0.81  0.67  1     0.80  1.07  42.30
CHF  1.01  0.83  1.24  1     1.33  52.56
SGD  0.76  0.62  0.93  0.75  1     39.42
RUB  0.02  0.02  0.02  0.02  0.03  1
Sun Mar 15 12:37:07 2015 YoshikuniJujo
import Numeric
t=init
m=map
main=interact$unlines.(\(x:s)->t x:s).m(t.unwords).w.m((\[r,n]->(read r,n)).words).lines
w r=("\\   ":n):zipWith(:)(m t n)(m(m i)$m((\x->m((/x).fst)r).fst)r)where n=m((++"  ").snd)r
i 1="1    "
i x=showFFloat(Just 2)x" "
182 symbols python2 failed test 1 Code error

Traceback (most recent call last): File "./code", line 6, in <module> for i in l[1:]:print ' '.join([i]+["%0.2f"%([d[i]/d[j],'1 '][i==j]) for j in l]) KeyError: '\\ '

Fri Oct 9 19:31:38 2015 BogdanShevchenko
import sys
d={}
l=['\ ']
for s in sys.stdin:a,b=s.split();d[b]=float(a);l+=[b]
print '   '.join(l)
for i in l[1:]:print '  '.join([i]+["%0.2f"%([d[i]/d[j],'1   '][i==j]) for j in l])
182 symbols python2 failed test 1 Code error

File "./code", line 5 for i in l[1:]:print ' '.join([i]+["%0.2f"%([d[i]/d[j]),'1 '][i==j] for j in l]) ^ SyntaxError: invalid syntax

Fri Oct 9 19:33:21 2015 BogdanShevchenko
import sys
d,l={},['\ ']
for s in sys.stdin:a,b=s.split();d[b]=float(a);l+=[b]
print '   '.join(l)
for i in l[1:]:print '  '.join([i]+["%0.2f"%([d[i]/d[j]),'1   '][i==j] for j in l])
183 symbols python2 failed test 1 Code error

File "./code", line 5 for i in l[1:]:print ' '.join([i]+[["%0.2f"%([d[i]/d[j]),'1 '][i==j] for j in l]) ^ SyntaxError: invalid syntax

Fri Oct 9 19:35:21 2015 BogdanShevchenko
import sys
d,l={},['\ ']
for s in sys.stdin:a,b=s.split();d[b]=float(a);l+=[b]
print '   '.join(l)
for i in l[1:]:print '  '.join([i]+[["%0.2f"%([d[i]/d[j]),'1   '][i==j] for j in l])
183 symbols python2 failed test 1 Code error

File "./code", line 4 print ' '.join([['\ ']+l) ^ SyntaxError: invalid syntax

Fri Oct 9 19:42:15 2015 BogdanShevchenko
import sys
d,l={},[]
for s in sys.stdin:a,b=s.split();d[b]=float(a);l+=[b]
print '   '.join([['\ ']+l)
for i in l:print '  '.join([i]+[["%0.2f"%([d[i]/d[j]),'1   '][i==j] for j in l])
182 symbols python2 failed test 1 Code error

File "./code", line 5 for i in l:print ' '.join([i]+[["%0.2f"%([d[i]/d[j]),'1 '][i==j] for j in l]) ^ SyntaxError: invalid syntax

Fri Oct 9 19:42:44 2015 BogdanShevchenko
import sys
d,l={},[]
for s in sys.stdin:a,b=s.split();d[b]=float(a);l+=[b]
print '   '.join(['\ ']+l)
for i in l:print '  '.join([i]+[["%0.2f"%([d[i]/d[j]),'1   '][i==j] for j in l])
184 symbols python2 failed test 1 Code error

File "./code", line 5 for i in l:print ' '.join([i]+[["%0.2f" % ([d[i]/d[j]),'1 '][i==j] for j in l]) ^ SyntaxError: invalid syntax

Fri Oct 9 19:43:34 2015 BogdanShevchenko
import sys
d,l={},[]
for s in sys.stdin:a,b=s.split();d[b]=float(a);l+=[b]
print '   '.join(['\ ']+l)
for i in l:print '  '.join([i]+[["%0.2f" % ([d[i]/d[j]),'1   '][i==j] for j in l])
182 symbols python2 failed test 1 Code error

File "./code", line 5 for i in l:print ' '.join([i]+[["%0.2f" % [d[i]/d[j],'1 '][i==j] for j in l]) ^ SyntaxError: invalid syntax

Fri Oct 9 19:46:55 2015 BogdanShevchenko
import sys
d,l={},[]
for s in sys.stdin:a,b=s.split();d[b]=float(a);l+=[b]
print '   '.join(['\ ']+l)
for i in l:print '  '.join([i]+[["%0.2f" % [d[i]/d[j],'1   '][i==j] for j in l])
184 symbols python2 failed test 1 Code error

File "./code", line 5 for i in l:print ' '.join([i]+[[("%0.2f" % [d[i]/d[j]),'1 '][i==j] for j in l]) ^ SyntaxError: invalid syntax

Fri Oct 9 19:47:28 2015 BogdanShevchenko
import sys
d,l={},[]
for s in sys.stdin:a,b=s.split();d[b]=float(a);l+=[b]
print '   '.join(['\ ']+l)
for i in l:print '  '.join([i]+[[("%0.2f" % [d[i]/d[j]),'1   '][i==j] for j in l])
183 symbols python2 failed test 1 Code error

Traceback (most recent call last): File "./code", line 5, in <module> for i in l:print ' '.join([i]+[[("%0.2f" % d[i]/d[j]),'1 '][i==j] for j in l]) TypeError: unsupported operand type(s) for /: 'str' and 'float'

Fri Oct 9 19:48:03 2015 BogdanShevchenko
import sys
d,l={},[]
for s in sys.stdin:a,b=s.split();d[b]=float(a);l+=[b]
print '   '.join(['\ ']+l)
for i in l:print '  '.join([i]+[[("%0.2f" % d[i]/d[j]),'1   '][i==j] for j in l])
189 symbols python2 failed test 1 Wrong answer
\    USD   EUR   AUD   CHF   SGD   RUB
USD  1     1.22  0.81  1.01  0.76  0.02
EUR  0.82  1     0.67  0.83  0.62  0.02
AUD  1.23  1.50  1     1.24  0.93  0.02
CHF  0.99  1.21  0.80  1     0.75  0.02
SGD  1.32  1.61  1.07  1.33  1     0.03
RUB  52.03  63.45  42.30  52.56  39.42  1   
instead of
\    USD   EUR   AUD   CHF   SGD   RUB
USD  1     0.82  1.23  0.99  1.32  52.03
EUR  1.22  1     1.50  1.21  1.61  63.45
AUD  0.81  0.67  1     0.80  1.07  42.30
CHF  1.01  0.83  1.24  1     1.33  52.56
SGD  0.76  0.62  0.93  0.75  1     39.42
RUB  0.02  0.02  0.02  0.02  0.03  1
Fri Oct 9 19:57:04 2015 BogdanShevchenko
import sys
d,l={},[]
for s in sys.stdin:a,b=s.split();d[b]=float(a);l+=[b]
print '   '.join(['\ ']+l)
for i in l:print '  '.join([i]+[["{0:.2f}".format(d[i]/d[j]),'1   '][i==j] for j in l])
189 symbols python2 failed test 1 Wrong answer
\    USD   EUR   AUD   CHF   SGD   RUB
USD  1     0.82  1.23  0.99  1.32  52.03
EUR  1.22  1     1.50  1.21  1.61  63.45
AUD  0.81  0.67  1     0.80  1.07  42.30
CHF  1.01  0.83  1.24  1     1.33  52.56
SGD  0.76  0.62  0.93  0.75  1     39.42
RUB  0.02  0.02  0.02  0.02  0.03  1   
instead of
\    USD   EUR   AUD   CHF   SGD   RUB
USD  1     0.82  1.23  0.99  1.32  52.03
EUR  1.22  1     1.50  1.21  1.61  63.45
AUD  0.81  0.67  1     0.80  1.07  42.30
CHF  1.01  0.83  1.24  1     1.33  52.56
SGD  0.76  0.62  0.93  0.75  1     39.42
RUB  0.02  0.02  0.02  0.02  0.03  1
Fri Oct 9 19:57:40 2015 BogdanShevchenko
import sys
d,l={},[]
for s in sys.stdin:a,b=s.split();d[b]=float(a);l+=[b]
print '   '.join(['\ ']+l)
for i in l:print '  '.join([i]+[["{0:.2f}".format(d[j]/d[i]),'1   '][i==j] for j in l])

View all solutions