์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ/BOJ_Java

[BOJ/Step6] 15596 : ์ •์ˆ˜ N๊ฐœ์˜ ํ•ฉ(JAVA)

NaNaRin๐Ÿ™ƒ 2021. 1. 9. 21:06

www.acmicpc.net/problem/15596

 

15596๋ฒˆ: ์ •์ˆ˜ N๊ฐœ์˜ ํ•ฉ

C++17, Java 8, Python 3, C11, PyPy3, C99, C++98, C++11, C++14, Python 2, PyPy2, Go, C99 (Clang), C++98 (Clang), C++11 (Clang), C++14 (Clang), C11 (Clang), C++17 (Clang)

www.acmicpc.net


๋ฌธ์ œ

์ •์ˆ˜ n๊ฐœ๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, n๊ฐœ์˜ ํ•ฉ์„ ๊ตฌํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•˜์‹œ์˜ค.

์ž‘์„ฑํ•ด์•ผ ํ•˜๋Š” ํ•จ์ˆ˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

  • C, C11, C (Clang), C11 (Clang): long long sum(int *a, int n);

    • a: ํ•ฉ์„ ๊ตฌํ•ด์•ผ ํ•˜๋Š” ์ •์ˆ˜ n๊ฐœ๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๋Š” ๋ฐฐ์—ด (0 ≤ a[i] ≤ 1,000,000, 1 ≤ n ≤ 3,000,000)

    • n: ํ•ฉ์„ ๊ตฌํ•ด์•ผ ํ•˜๋Š” ์ •์ˆ˜์˜ ๊ฐœ์ˆ˜

    • ๋ฆฌํ„ด๊ฐ’: a์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ์ •์ˆ˜ n๊ฐœ์˜ ํ•ฉ

  • C++, C++11, C++14, C++17, C++ (Clang), C++11 (Clang), C++14 (Clang), C++17 (Clang): long long sum(std::vector<int> &a);

    • a: ํ•ฉ์„ ๊ตฌํ•ด์•ผ ํ•˜๋Š” ์ •์ˆ˜ n๊ฐœ๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๋Š” ๋ฐฐ์—ด (0 ≤ a[i] ≤ 1,000,000, 1 ≤ n ≤ 3,000,000)

    • ๋ฆฌํ„ด๊ฐ’: a์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ์ •์ˆ˜ n๊ฐœ์˜ ํ•ฉ

  • Python 2, Python 3, PyPy, PyPy3: def solve(a: list) -> int

    • a: ํ•ฉ์„ ๊ตฌํ•ด์•ผ ํ•˜๋Š” ์ •์ˆ˜ n๊ฐœ๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๋Š” ๋ฆฌ์ŠคํŠธ (0 ≤ a[i] ≤ 1,000,000, 1 ≤ n ≤ 3,000,000)

    • ๋ฆฌํ„ด๊ฐ’: a์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ์ •์ˆ˜ n๊ฐœ์˜ ํ•ฉ (์ •์ˆ˜)

  • Java: long sum(int[] a); (ํด๋ž˜์Šค ์ด๋ฆ„: Test)

    • a: ํ•ฉ์„ ๊ตฌํ•ด์•ผ ํ•˜๋Š” ์ •์ˆ˜ n๊ฐœ๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๋Š” ๋ฐฐ์—ด (0 ≤ a[i] ≤ 1,000,000, 1 ≤ n ≤ 3,000,000)

    • ๋ฆฌํ„ด๊ฐ’: a์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ์ •์ˆ˜ n๊ฐœ์˜ ํ•ฉ

  • Go: sum(a []int) int

    • a: ํ•ฉ์„ ๊ตฌํ•ด์•ผ ํ•˜๋Š” ์ •์ˆ˜ n๊ฐœ๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๋Š” ๋ฐฐ์—ด (0 ≤ a[i] ≤ 1,000,000, 1 ≤ n ≤ 3,000,000)

    • ๋ฆฌํ„ด๊ฐ’: a์— ํฌํ•จ๋˜์–ด ์žˆ๋Š” ์ •์ˆ˜ n๊ฐœ์˜ ํ•ฉ


ํ’€์ด

 

public class B15596 {
	
	long sum(int[] a) {
		long total = 0;
		
		for(int i = 0; i < a.length; i++) {
			total += a[i];
		}
		return total;
	}

}