01-25 23:05
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

[BAEKJOON] ๋ฐฑ์ค€ ์ž…์ถœ๋ ฅ 11720 :: ์ˆซ์ž์˜ ํ•ฉ JAVA ๋ณธ๋ฌธ

Algorithm/Baekjoon

[BAEKJOON] ๋ฐฑ์ค€ ์ž…์ถœ๋ ฅ 11720 :: ์ˆซ์ž์˜ ํ•ฉ JAVA

miinsun 2022. 3. 11. 00:11

 

๐Ÿ’ฌ  ๋ฌธ์ œ ์„ค๋ช…

N๊ฐœ์˜ ์ˆซ์ž๊ฐ€ ๊ณต๋ฐฑ ์—†์ด ์“ฐ์—ฌ์žˆ๋‹ค. ์ด ์ˆซ์ž๋ฅผ ๋ชจ๋‘ ํ•ฉํ•ด์„œ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

 

๐Ÿ”จ  ์ž…์ถœ๋ ฅ ์˜ˆ

์ž…๋ ฅ 

  • ์ฒซ์งธ ์ค„์— ์ˆซ์ž์˜ ๊ฐœ์ˆ˜ N (1 ≤ N ≤ 100)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์— ์ˆซ์ž N๊ฐœ๊ฐ€ ๊ณต๋ฐฑ์—†์ด ์ฃผ์–ด์ง„๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ 1)

1
1

 

์˜ˆ์ œ ์ž…๋ ฅ 2)

5
54321

 

์˜ˆ์ œ ์ž…๋ ฅ 3)

25
7000000000000000000000000

 

์ถœ๋ ฅ

  • ์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์ง„ ์ˆซ์ž N๊ฐœ์˜ ํ•ฉ์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

์˜ˆ์ œ ์ถœ๋ ฅ 1)

1

 

์˜ˆ์ œ ์ถœ๋ ฅ 2)

15

 

์˜ˆ์ œ ์ถœ๋ ฅ 3)

7

โ€‹

 

๐Ÿ’ป  Main.java

/* ๋ฐฑ์ค€ ์ž…์ถœ๋ ฅ - 11720 :: ์ˆซ์ž์˜ ํ•ฉ */
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		
		int sum = 0;
		for(int i = 0; i < n; i++) {
			sum += s.charAt(i) - '0';
		}
		
		System.out.println(sum);
		
		sc.close();
	}
}
Comments