문제
Joisino is working as a receptionist at a theater.
The theater has 100000 seats, numbered from 1 to 100000.
According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat Li to Seat Ri (inclusive).
How many people are sitting at the theater now?
입력
The first line of the input contains an integer T, the number of test sets (1 ≤ T ≤ 10).
For each test set, the input is given from Standard Input in the following format:
2 1 24 30 2 6 8 3 3 |
출력
For each test case, print “#T”(test case number), and the number of people sitting at the theater.
#1 7 #2 4 |
코드
import java.util.Scanner;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i=0; i<t; i++){
int n = sc.nextInt();
int sum = 0;
for(int j=0; j<n; j++){
int L = sc.nextInt();
int R = sc.nextInt();
sum += R - L +1;
}
System.out.printf("#%d %d\n",i+1,sum);
}
}
}
'SW expert Academy > D2' 카테고리의 다른 글
[SW Expert Academy] 2357번 September 9 (0) | 2023.05.17 |
---|---|
[SW Expert Academy] 1204번 최빈수 구하기 (0) | 2023.05.17 |
[SW Expert Academy] 1284번 수도 요금 경쟁 (0) | 2023.05.17 |
[SW Expert Academy] 1288번 새로운 불면증 치료법 (0) | 2023.05.17 |
[SW Expert Academy] 1928번 Base64 Decoder 변형 문제 (0) | 2023.05.17 |