Skip to content

Commit 909dcb9

Browse files
authored
[BOJ] 5949 Adding Commas (B3)
1 parent 5ff654c commit 909dcb9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

정건우/7주차/260212.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//https://www.acmicpc.net/problem/5949
2+
import java.util.Scanner;
3+
4+
public class BOJ_B3_5949_AddingCommas {
5+
public static void main(String[] args) {
6+
Scanner scann = new Scanner(System.in);
7+
StringBuilder sb = new StringBuilder();
8+
9+
String N = scann.nextLine();
10+
int cnt = 0;
11+
12+
for (int i = N.length()-1; i >= 0; i--) {
13+
if(cnt % 3 == 0) sb.append(',');
14+
15+
sb.append(N.charAt(i));
16+
17+
cnt++;
18+
}
19+
20+
sb = sb.reverse();
21+
22+
if(sb.charAt(sb.length()-1) == ','){
23+
sb.setLength(sb.length()-1);
24+
}
25+
26+
System.out.println(sb.toString());
27+
}
28+
}

0 commit comments

Comments
 (0)