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


57 symbols perl failed test 1 Code error

syntax error at ./code line 2, near "$h{" Unmatched right curly bracket at ./code line 2, at end of line Missing right curly or square bracket at ./code line 2, at end of line Execution of ./code aborted due to compilation errors.

Fri Jun 27 16:55:03 2014 dionys
perl -pla
$h{$F[0]}+=$F[1]}for(sort keys%h){$_.=" $h{$_}"
203 symbols python3 failed test 1 Code error

Traceback (most recent call last): File "./code", line 2, in <module> for line in open('list.txt'): FileNotFoundError: [Errno 2] No such file or directory: 'list.txt'

Wed Jul 2 13:34:02 2014 BLiT_Racing
results = {}
for line in open('list.txt'):
    name, num = line.split()
    if name in results:
        results[name] = results[name] + int(num)
    else:
        results[name] = int(num)
print(results)
205 symbols python3 failed test 1 Code error

Traceback (most recent call last): File "./code", line 4, in <module> for line in data: TypeError: 'builtin_function_or_method' object is not iterable

Wed Jul 2 14:23:15 2014 BLiT_Racing
data = input

results = {}
for line in data:
    name, num = line.split()
    if name in results:
        results[name] = results[name] + int(num)
    else:
        results[name] = int(num)
print(results)
160 symbols python2 failed test 1 Code error

Traceback (most recent call last): File "./code", line 3, in <module> l=raw_input().split() EOFError: EOF when reading a line

Sun Jul 20 18:41:21 2014 LLcoolNJ
d={}
while True:
 l=raw_input().split()
 if not len(l):
  break
 if l[0] in d:
  d[l[0]]+=int(l[1])
 else:
  d[l[0]]=int(l[1])
for i in sorted(d):
 print i,d[i]
141 symbols python3 failed test 1 Wrong answer
apple 120086038
grape 740600
orange 530310250
instead of
apple 2440
grape 1340
orange 1090
Fri Aug 8 22:23:46 2014 z423x5c6
import sys
a={}
for i in sys.stdin:
 i=i[:-1].split()
 if i[0]in a:a[i[0]]+=i[1]
 else:a[i[0]]=i[1]
for k in sorted(a.keys()):
 print(k,a[k])
151 symbols python3 failed test 1 Wrong answer
apple 2098
grape 1340
orange 1090
instead of
apple 2440
grape 1340
orange 1090
Fri Aug 8 22:24:37 2014 z423x5c6
import sys
a={}
for i in sys.stdin:
 i=i[:-1].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])
146 symbols python3 failed test 1 Code error

File "./code", line 3 for i in sys.stdin:i=i.strip('\n').split();try:a[i[0]]+=int(i[1]);except:a[i[0]]=int(i[1]) ^ SyntaxError: invalid syntax

Mon Aug 11 20:25:47 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])

View all solutions