問題描述是在這裏:http://www.spoj.pl/problems/FASHION/SPOJ時裝給運行時錯誤的Python
過程:注意到兩個列表作爲輸入,使用Python中sort()方法對它們進行排序,然後打印總和
代碼:
import sys,os
#Need to maximize the product of two lists
def process(index,line):
p=line.split(" ")
#print 'Line after splitting',p
for i in p:
if(index==0):
men.append(int(i))
else:
women.append(int(i))
global men
global women
men=[]
women=[]
''' First, you enter number of times you want to compare .
Second, you enter number of men/women
Then, you enter the real data
'''
n=int(raw_input()) #This is for number of shows
num = int(raw_input()) #This is number of men/women
for t in range(0,n): #Do this "n" times
men = []
women = []
for i in range(0,2): #Now, enter the men data first and women next
line=raw_input()
process(i,line)
p=0
temp = []
men.sort()
women.sort()
for i in range(0,num):
p = p + men[i] * women[i]
print p
問題:它不斷給運行時錯誤:(
我所遇到的一些情況:
In [16]: %run /home/crazyabtliv/SPOJ/Fashion.py
2
3
1 1 1
2 3 4
9
4 5 6
0 9 8
94
In [14]: %run /home/crazyabtliv/SPOJ/Fashion.py
1
5
1 1 0 0 0
10 10 9 9 9
20
謝謝!
你的[運行時錯誤](http://hs.spoj.pl/embed/guide)的代碼是什麼? – joaquin 2011-12-29 07:41:18
爲什麼不嘗試用[測試輸入SPOJ在問題頁面中提供您?](http://www.spoj.pl/problems/FASHION/)來測試您的代碼。你有相同的輸出嗎? – joaquin 2011-12-29 07:57:43