将下面java代码改为python代码 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); JinCheng process1 = new JinCheng(); JinCheng process2 = new JinCheng(); JinCheng process3 = new JinCheng(); JinCheng[] processes = {process1,process2,process3}; for (JinCheng process : processes) { process.name = scanner.next(); process.enterTime = scanner.nextInt(); process.runningTime = scanner.nextInt(); } int i=0; while(i < processes.length - 1) { int j = 0; while(j < processes.length -1 - i) { if (processes[j+1].enterTime < processes[j].enterTime) { JinCheng tmp = processes[j]; processes[j] = processes[j+1]; processes[j+1] = tmp; } j++; } i++; } zgxyb_sf(processes); System.out.println(process1.zzsj + " " + process2.zzsj + " " + process3.zzsj); } private static void zgxyb_sf(JinCheng[] processes) { processes[0].startTime = processes[0].enterTime; processes[0].jssj = processes[0].startTime+processes[0].runningTime; processes[1].responseRatio = 1 + (float)(processes[0].jssj- processes[1].enterTime)/(processes[1].runningTime); processes[2].responseRatio = 1 + (float)(processes[0].jssj - processes[2].enterTime)/(processes[2].runningTime); if (processes[1].responseRatio < processes[2].responseRatio) { if (processes[2].enterTime > processes[0].jssj) { processes[2].startTime = processes[2].enterTime; processes[2].jssj = processes[2].startTime + processes[2].runningTime; if (processes[1].enterTime > processes[2].jssj) { processes[1].startTime = processes[1].enterTime; }else { processes[1].jssj = processes[2].jssj; } processes[1].jssj= processes[1].startTime + processes[1].runningTime; }else { processes[2].startTime = processes[0].jssj; processes[2].jssj = processes[2].startTime + processes[2].runningTime; if (processes[2].jssj < processes[1].enterTime) { processes[1].startTime = processes[1].enterTime; }else { processes[1].startTime = processes[2].jssj; } processes[1].jssj= processes[1].startTime + processes[1].runningTime; } }else { if (processes[1].enterTime > processes[0].jssj) { processes[1].startTime = processes[1].enterTime; processes[1].jssj = processes[1].startTime + processes[1].runningTime; if (processes[2].enterTime > processes[1].jssj) { processes[2].startTime = processes[2].enterTime; }else { processes[2].startTime = processes[1].jssj; } processes[2].jssj = processes[2].startTime + processes[2].runningTime; }else { processes[1].startTime = processes[0].jssj; processes[1].jssj = processes[1].startTime + processes[1].runningTime; if (processes[2].enterTime > processes[1].jssj) { processes[2].startTime = processes[2].enterTime; }else { processes[2].startTime = processes[1].jssj; } processes[2].jssj = processes[2].startTime + processes[2].runningTime; } } processes[0].zzsj = processes[0].jssj - processes[0].enterTime; processes[1].zzsj =processes[1].jssj - processes[1].enterTime; processes[2].zzsj =processes[2].jssj - processes[2].enterTime; } } class JinCheng{ public String name; public int enterTime; public int runningTime; public int startTime; public int jssj; public float responseRatio; public int zzsj; }
时间: 2023-12-06 17:03:37 浏览: 103
以下是将Java代码翻译成Python代码的结果:
```python
class JinCheng:
def __init__(self):
self.name = ""
self.enterTime = 0
self.runningTime = 0
self.startTime = 0
self.jssj = 0
self.responseRatio = 0.0
self.zzsj = 0
def zgxyb_sf(processes):
processes[0].startTime = processes[0].enterTime
processes[0].jssj = processes[0].startTime + processes[0].runningTime
processes[1].responseRatio = 1 + (processes[0].jssj - processes[1].enterTime) / processes[1].runningTime
processes[2].responseRatio = 1 + (processes[0].jssj - processes[2].enterTime) / processes[2].runningTime
if processes[1].responseRatio < processes[2].responseRatio:
if processes[2].enterTime > processes[0].jssj:
processes[2].startTime = processes[2].enterTime
processes[2].jssj = processes[2].startTime + processes[2].runningTime
if processes[1].enterTime > processes[2].jssj:
processes[1].startTime = processes[1].enterTime
else:
processes[1].jssj = processes[2].jssj
processes[1].jssj = processes[1].startTime + processes[1].runningTime
else:
processes[2].startTime = processes[0].jssj
processes[2].jssj = processes[2].startTime + processes[2].runningTime
if processes[2].jssj < processes[1].enterTime:
processes[1].startTime = processes[1].enterTime
else:
processes[1].startTime = processes[2].jssj
processes[1].jssj = processes[1].startTime + processes[1].runningTime
else:
if processes[1].enterTime > processes[0].jssj:
processes[1].startTime = processes[1].enterTime
processes[1].jssj = processes[1].startTime + processes[1].runningTime
if processes[2].enterTime > processes[1].jssj:
processes[2].startTime = processes[2].enterTime
else:
processes[2].startTime = processes[1].jssj
processes[2].jssj = processes[2].startTime + processes[2].runningTime
else:
processes[1].startTime = processes[0].jssj
processes[1].jssj = processes[1].startTime + processes[1].runningTime
if processes[2].enterTime > processes[1].jssj:
processes[2].startTime = processes[2].enterTime
else:
processes[2].startTime = processes[1].jssj
processes[2].jssj = processes[2].startTime + processes[2].runningTime
processes[0].zzsj = processes[0].jssj - processes[0].enterTime
processes[1].zzsj = processes[1].jssj - processes[1].enterTime
processes[2].zzsj = processes[2].jssj - processes[2].enterTime
if __name__ == "__main__":
processes = [JinCheng(), JinCheng(), JinCheng()]
for process in processes:
process.name = input()
process.enterTime = int(input())
process.runningTime = int(input())
i = 0
while i < len(processes) - 1:
j = 0
while j < len(processes) - 1 - i:
if processes[j+1].enterTime < processes[j].enterTime:
tmp = processes[j]
processes[j] = processes[j+1]
processes[j+1] = tmp
j += 1
i += 1
zgxyb_sf(processes)
print(processes[0].zzsj, processes[1].zzsj, processes[2].zzsj)
```
注意:Python中没有类似Java中的Scanner类,因此需要使用input()函数来获取用户的输入。
阅读全文