문제 링크: https://www.acmicpc.net/problem/5949
5949번: Adding Commas
Bessie is working with large numbers N (1 <= N <= 2,000,000,000) like 153920529 and realizes that the numbers would be a lot easier to read with commas inserted every three digits (as is normally done in the USA; some countries prefer to use periods every
www.acmicpc.net
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
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
string s, ans;
cin >> s;
int sz = s.size();
if(sz > 9) {
s.insert(1, ",");
s.insert(5, ",");
s.insert(9, ",");
}
else if(sz > 6) {
s.insert(sz - 6, ",");
s.insert(sz - 2, ",");
}
else if(sz > 3) {
s.insert(sz - 3, ",");
}
cout << s;
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size();
for(int i = 0; i < n; i++) {
if(i > 0 && (n - i) % 3 == 0) cout << ',';
cout << s[i];
}
cout << '\n';
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'USACO > Bronze' 카테고리의 다른 글
백준 5957 Cleaning the Dishes (USACO January 2011 Bronze 2번) (0) | 2020.04.08 |
---|---|
백준 5956 Symmetry (USACO January 2011 Bronze 1번) (0) | 2020.04.08 |
백준 5948 Bad Random Numbers (USACO December 2010 Bronze 2번) (0) | 2020.04.06 |
백준 5947 Book Club (USACO December 2010 Bronze 1번) (0) | 2020.04.06 |
백준 5940 Math Practice (USACO November 2010 Bronze 3번) (0) | 2020.03.24 |