-
1292 쉽게 푸는 문제백준/구현 2021. 10. 18. 19:58
https://www.acmicpc.net/problem/1292
1292번: 쉽게 푸는 문제
첫째 줄에 구간의 시작과 끝을 나타내는 정수 A, B(1 ≤ A ≤ B ≤ 1,000)가 주어진다. 즉, 수열에서 A번째 숫자부터 B번째 숫자까지 합을 구하면 된다.
www.acmicpc.net
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); StringTokenizer st = new StringTokenizer(s, " "); int N = Integer.parseInt(st.nextToken()); int M = Integer.parseInt(st.nextToken()); List<Integer> list = new ArrayList<>(); for(int i=1; i<1001;i++) { for(int j=0;j<i;j++) { list.add(i); //이렇게 list에 집어넣으면, index=0부터 list에 들어감 //(list는 index를 가지고 있음) } } int sum =0; for(int k=N-1;k<M;k++) { sum+=list.get(k); } System.out.println(sum); } }
참고 :
https://broship.tistory.com/157
자바 - 구현 - 백준 1292 쉽게 푸는 문제
문제 문제해결 import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class S4_1292 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a..
broship.tistory.com