Subtotal

Output the subtotal of the amount of each product.
Output by changing sequence in ascending order of name.

IN

apple 1200
orange 530
grape 740
orange 310
apple 860
grape 600
orange 250
apple 380

OUT

apple 2440
grape 1340
orange 1090

IN

grape -1000
orange 500
apple 700
banana 480
banana 640
apple 1200
grape 800

OUT

apple 1900
banana 1120
grape -200
orange 500

IN

grape 1500
apple 0
orange -200
grape -1500
orange 200
banana 300
banana -300

OUT

apple 0
banana 0
grape 0
orange 0
Login to submit solution


23 symbols pyth
Wed Nov 23 17:25:31 2016 Sait2000
VSuXhHGseHcR;.zHpNpd@HN
25 symbols pyth
Mon Sep 19 17:00:32 2016 Sait2000
VcR;.z XhNHseN)VSHpNpd@HN
49 symbols perl
Fri Sep 26 17:03:20 2014 vakorol
#!/usr/bin/perl -pl
/\S+/;$h{$&}+=$'}for(sort keys%h){s/$/ $h{$_}/
51 symbols perl
Fri Jun 27 16:55:48 2014 dionys
#!/usr/bin/perl -pla
$h{$F[0]}+=$F[1]}for(sort keys%h){$_.=" $h{$_}"
54 symbols perl
Sun Jun 22 23:00:12 2014 avkhozov
#!/usr/bin/perl -nla
$h{$F[0]}+=$F[1]}{print"$_ $h{$_}"for sort keys%h
134 symbols python3
Sun Feb 22 15:46:12 2015 z423x5c6
import sys,collections as c
a=c.Counter()
for i in sys.stdin:
 b=i.split()
 a[b[0]]+=int(b[1])
for i in sorted(a.keys()):print(i,a[i])
152 symbols python3
Mon Aug 11 20:24:50 2014 z423x5c6
import sys
a={}
for i in sys.stdin:
 i=i.strip('\n').split()
 try:a[i[0]]+=int(i[1])
 except:a[i[0]]=int(i[1])
for k in sorted(a.keys()):
 print(k,a[k])
158 symbols python3
Fri Aug 8 22:25:59 2014 z423x5c6
import sys
a={}
for i in sys.stdin:
 i=i.strip('\n').split()
 if i[0]in a:a[i[0]]+=int(i[1])
 else:a[i[0]]=int(i[1])
for k in sorted(a.keys()):
 print(k,a[k])
158 symbols python3
Mon Aug 11 20:24:03 2014 z423x5c6
import sys
a={}
for i in sys.stdin:
 i=i.strip('\n').split()
 try:
  a[i[0]]+=int(i[1])
 except:
  a[i[0]]=int(i[1])
for k in sorted(a.keys()):
 print(k,a[k])
177 symbols haskell
Fri Mar 13 16:07:45 2015 YoshikuniJujo
import Data.List
main=interact$unlines.map(\(n,a)->n++" "++show a).map(\p->(fst$head p,sum$map snd p)).groupBy((.fst).(==).fst).sort.map(\l->let[n,a]=words l in(n,read a)).lines
256 symbols haskell
Fri Jun 27 03:40:56 2014 salvipeter
import Control.Arrow
import Data.Function
import Data.List
r x=(a,read b)where[a,b]=words x
a x=map(fst.head&&&foldr1(+).map snd)$groupBy(on(==)fst)$sortBy(on compare fst)x
s(a,b)=a++' ':show b
main=do{p<-fmap(map r.lines)getContents;mapM_(putStrLn.s)$a p}
287 symbols python2
Sun Jun 22 21:15:09 2014 KoukiMino
import sys
lines=map(str,sys.stdin.read().splitlines())
out={}
for line in lines:
	(item,price) = map(str,line.split(' '))
	if out.has_key(item):
		out[item] += int(price)
	else:
		out[item] = int(price)
for item,price in sorted(out.items(),key=lambda x:x[0]):
	print item+" "+str(price)

View all solutions