[swexpert] 2369. B theater (java)

728x90
반응형

풀이.

 

극장에는 n줄으로 이루어져있다 

l ~ r 만큼 사람들이 연속으로 앉아있다 

인원수는 r-l+1이다. n줄의 인원수를 더해서 출력하면 된다. 

package com.ssafy.edu;

import java.util.Scanner;

public class Solution {

	public static void main(String[] args) {
		
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		for (int i = 0; i < t; i++) {
			int n=sc.nextInt();
			long 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);
		}
		sc.close();
	}
	
	
}
	


728x90
반응형
TAGS.

Comments