我是Python 3的新手,正在使用Hackerrank上的"Breaking the Records" problem。当我使用字符串输入时,我的代码在IDLE中正常工作,但我不知道如何将Hackerrank的输入更改为像字符串一样“可用”的东西。基本上我尝试过的所有其他Hackerrank练习也遇到了同样的问题。
问题是对于输入,“第一行包含表示游戏数量的整数 n ,第二行包含 n 间隔分隔的整数s0,s1,... s(n-1)“
的各自值这是我到目前为止尝试过的代码。
select T1.RegionID
, T1.RegionDescription
, T1.MaxSoldQuantity
, N2.ProductName
, N2.ProductID
from (
select NESTED.RegionID
, NESTED.RegionDescription
, max(NESTED.SoldQuantity) as MaxSoldQuantity
from (
select R.RegionID as RegionID
, R.RegionDescription as RegionDescription
, P.ProductID as ProductID
, P.ProductName as ProductName
, sum(OD.Quantity) as SoldQuantity
from Region as R inner join Territories as T on R.RegionID = T.RegionID
inner join EmployeeTerritories as ET on T.TerritoryID = ET.TerritoryID
inner join Employees as E on ET.EmployeeID = E.EmployeeID
inner join Orders as O on E.EmployeeID = O.EmployeeID
inner join [Order Details] as OD on O.OrderID = OD.OrderID
inner join Products as P on OD.ProductID = P.ProductID
group by R.RegionID, R.RegionDescription, P.ProductID, P.ProductName
) as NESTED
group by NESTED.RegionID, NESTED.RegionDescription ) T1
inner join (
select R.RegionID as RegionID
, R.RegionDescription as RegionDescription
, P.ProductID as ProductID
, P.ProductName as ProductName
, sum(OD.Quantity) as SoldQuantity
from Region as R inner join Territories as T on R.RegionID = T.RegionID
inner join EmployeeTerritories as ET on T.TerritoryID = ET.TerritoryID
inner join Employees as E on ET.EmployeeID = E.EmployeeID
inner join Orders as O on E.EmployeeID = O.EmployeeID
inner join [Order Details] as OD on O.OrderID = OD.OrderID
inner join Products as P on OD.ProductID = P.ProductID
group by R.RegionID, R.RegionDescription, P.ProductID, P.ProductName
) N2 on N2.SoldQuantity = T1.MaxSoldQuantity
答案 0 :(得分:0)
这就是我的所作所为:
#!/bin/python3
import sys
def breakingRecords(score):
# Complete this function
min = -1
minCount = 0
maxCount = 0
for s in score:
if min == -1:
min = s
max = s
continue
if s < min:
min = s
minCount+=1
if s > max:
max = s
maxCount+=1
return maxCount, minCount
if __name__ == "__main__":
n = int(input().strip())
score = map(int,input().strip().split(' '))
result = breakingRecords(score)
print(" ".join(map(str, result)))
我认为我将原始代码部分保留在 - if __name__ == "__main__":
答案 1 :(得分:0)
// Complete the breakingRecords function below.
static int[] breakingRecords(int[] scores) {
int high, low;
high = low = -1;
int h,l;
h = l = 0;
int[] list = new int[2];
low = scores[0];
for(int i=1; i<=scores.length; i++){
if(high < scores[i -1]){
high = scores[i -1];
h++;
}
if(i < scores.length){
if(low > scores[i]){
low = scores[i];
l++;
}
}}
list[0] = h - 1;
list[1] = l ;
return list;
}