[Java | 백준 2577번] 숫자의 개수
· 테크· Java
Java
백준 2577번 www.acmicpc.net/problem/2577
풀이
이 문제에서 주의할 점은 0~9까지의 숫자를 검사해야 된다는 것이다.
출력의 둘째줄만 보고 1~9까지 숫자 검사가 아닌 첫째줄에는 0 이 몇 번 쓰였는지 검사해야 한다는 것을 조심하자!
for 문을 이용해서 곱해서 나온 값을 charAt() 으로 하나씩 가져와서 숫자가 맞는지 비교한다.
|
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
|
import java.util.*;
public class Array_2577 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long a = sc.nextLong();
long b = sc.nextLong();
long c = sc.nextLong();
sc.nextLine();
String result = String.valueOf(a*b*c);
for (int j=0; j<=9; j++) {
int cnt = 0;
for (int i=0; i<result.length(); i++) {
if(j==result.charAt(i)-'0') {
cnt++;
}
}
System.out.println(cnt);
}
sc.close();
}
}
|
cs |
Comments
No comments yet. Be the first!
319 posts in 테크
- 368Supabase 프로젝트 복사하기 (Restore to a New Project)NEW
- 341Migrating from Permanent Access Tokens to Token Exchange — Why Order Matters
- 326Startup & Product Glossary: Terms Every Solo Founder Should Know
- 325Context Management — How I Do It Now
- 324Claude Code Routines vs Cowork Schedule — What's the Difference?
1–5 / 319