-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_11720.java
More file actions
57 lines (50 loc) ยท 1.33 KB
/
_11720.java
File metadata and controls
57 lines (50 loc) ยท 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package backjoon;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
// https://www.acmicpc.net/problem/11720
// ์ซ์์ ํฉ
public class _11720 {
public static void main(String[] args) throws IOException {
// sol1 ๋ฐฐ์ด์ฌ์ฉ
// memory 11652 runtime 84
/*
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int cnt = Integer.parseInt(br.readLine());
String[] nums = br.readLine().split("");
int sum = 0;
//Convert String array to int array
int[] intNums = new int[cnt];
for(int i=0; i<cnt; i++){
intNums[i] = Integer.parseInt(nums[i]);
}
//Sum
for(int n : intNums){
sum += n;
}
System.out.println(sum);
*/
// sol2 ๋ฐฐ์ด์ฌ์ฉํ์ง์๊ณ getBytes()์ฌ์ฉ
// memory 11480 runtime 80
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine(); // cnt๋ ์ฌ์ฉํ์ง ์์ผ๋ฏ๋ก ์
๋ ฅ๋ง ๋ฐ์
int sum = 0;
for(byte n : br.readLine().getBytes()){
sum += (n - 48);
//sum += (n - '0'); // n-48๊ณผ n-'0'์ ๊ฐ์ ์๋ฏธ์ธ๋ฐ ๊ทธ ์ด์ ๋ ์์คํค์ฝ๋์์ ์ซ์ 1์ 49๋ถํฐ ์์ํ๊ธฐ๋๋ฌธ์ ์ซ์ 0์ธ 48์ ๋นผ์ค์ผ ํจ.
}
System.out.println(sum);
}
}
/*
input
1
1
output
1
input
25
7000000000000000000000000
output
7
*/