哇这道题写的我真是...
一直再往深处想 让你输入绿灯和红灯的时间有啥用根本没用到我以为还要考虑各种情况绿灯时间够不够用不用再等一个红灯
想复杂了 就是遇到绿灯直接过 红灯等一下 黄灯多等一个红灯 就这么简单的问题
package Main;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int r = 0;
int y = 0;
int g = 0;
int n = 0;
int s = 0;
r = sc.nextInt();
y = sc.nextInt();
g = sc.nextInt();
n = sc.nextInt();
// 用一个二位数组存放小明的记录
int[][] a = new int[n][2];
for (int i = 0; i < n; i++) {
a[i][0] = sc.nextInt();
a[i][1] = sc.nextInt();
}
// 遍历进行判断
for (int i = 0; i < a.length; i++) {
if (a[i][0] == 0) {
// 如果为0 直接加进总时间
s = s + a[i][1];
} else if (a[i][0] == 1) {
// 如果为1说明是红灯 需要等一下 也直接加进去
s = s + a[i][1];
} else if (a[i][0] == 2) {
// 如果是黄灯 需要等一个黄灯 和一个红灯
s = s + a[i][1] + r;
}
}
System.out.println(s);
sc.close();
}
}