Question number: | 201812-1 |
Question name: | Xiao Ming goes to school |
time limit: | 1.0s |
Memory limit: | 512.0MB |
Problem Description: | Topic background Xiao Ming is a student at the Affiliated Middle School of the Handong University of Political Science and Law. He rides a bicycle to and from home and school every day. In order to get as much sleep as possible, he hopes to be able to estimate the time he needs to go to school. He needs to pass several sections of roads to go to school, and there is at most one traffic light between two adjacent sections of roads. Problem Description On the way to school, Xiao Ming recorded the time of each section of the road, the color of each traffic light when Xiao Ming arrived at the intersection and the countdown seconds. I hope you can help me calculate the time Xiao Ming spent in school this time. Input format The first line of input contains three positive integers r, y, g separated by spaces, indicating the setting of traffic lights. None of these three numbers exceed 106. Output format Output a number to indicate the time Xiao Ming spent in school this time. Sample input 30 3 30 Sample output 70 Sample description Xiao Ming first passes the first section of the road, which takes 10 seconds, then waits for 5 seconds for the red light, and then passes through the second section of the road, which takes 11 seconds, then waits for 2 seconds for the yellow light and 30 seconds for the red light, and then passes through the third section The fourth section of road takes 6 and 3 seconds respectively, and then passes the green light, and then passes through the last section of road, which takes 3 seconds. A total of 10 + 5 + 11 + 2 + 30 + 6 + 3 + 3 = 70 seconds. Evaluation use case scale and conventions There are no signal lights in test points 1, 2. |
import java.util.Scanner;
public class 小明上学 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int r=sc.nextInt();
int y=sc.nextInt();
int g=sc.nextInt();
int n=sc.nextInt();
int[] a=new int[n];
int[] b=new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
b[i]=sc.nextInt();
}
int res=0;
for(int i=0;i<n;i++){
if(a[i]==0){
res+=b[i];
}else if(a[i]==1){
res+=b[i];
}else if(a[i]==2){
res+=b[i]+r;
}else if(a[i]==3){
res+=0;
}
}
System.out.println(res);
}
}