https://www.acmicpc.net/problem/11720
알고리즘을 다시 하려니 잘 잡히지 않아,
다시 기초부터 해야겠다는 생각에 Do it 알고리즘 코딩테스트 책을 샀다.
다시 차근차근 해나가야겠다.
이건 이번에 풀어본 풀이
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String line2 = br.readLine();
String[] line2Arr = line2.split("");
int sum=0;
for(int i=0; i<n; i++){
sum+= Integer.parseInt(line2Arr[i]);
}
System.out.println(sum);
}
}
이건 백준 기록에 남아있던 예전에 풀었던 풀이...
오랜만에 하니 스캐너쓰는 법도 까먹었다...
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
String str = sc.next();
int sum=0;
for(int i=0;i<a;i++){
sum += str.charAt(i)-'0';
}
System.out.println(sum);
}
}'알고리즘 > 백준' 카테고리의 다른 글
| [백준] 11659 - 자바 (1) | 2025.07.17 |
|---|---|
| [백준] 1546 - 자바 (1) | 2025.07.16 |
| [백준] 17219 - 자바 (1) | 2025.06.25 |
| [백준] 1874 - 자바 (2) | 2025.06.24 |
| [백준] 15829 - 자바 (1) | 2025.06.12 |