1012.
[풀이]
소수점 7자리에서 반올림 해 6자리까지 나타내는 방법은 아래 두 가지 방법이 있다.
#include <bits/stdc++.h>
using namespace std;
int main() {
float n;
cin >> n;
cout << setprecision(6) << fixed << n;
}
#include <bits/stdc++.h>
using namespace std;
int main() {
float n;
cin >> n;
cout.precision(6);
cout << fixed << n;
}
1015.
[풀이]
#include "iostream"
#include <iomanip>
using namespace std;
int main(void) {
float f;
cin >> f;
cout << setprecision(2) << fixed << f;
}
1018.
[풀이]
구분자 : 를 기준으로 입력 받아야 할 때, 문제가 복잡해질수록 cin 보다는 scanf를 사용하는 것이 좋다.
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int a, b;
char c;
cin >> a >> c >> b;
cout << a << ':' << b;
}
#include <bits/stdc++.h>
using namespace std;
int main(){
int hour, min;
scanf("%d:%d", &hour, &min);
cout << hour << ':' << min;
}
1019.
[풀이]
#include <bits/stdc++.h>
using namespace std;
int main(){
int y,m,d;
scanf("%d.%d.%d", &y, &m, &d);
printf("%04d.%02d.%02d", y, m, d);
}
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int y, m, d;
char dot;
cin >> y >> dot >> m >> dot >> d;
cout.width(4); cout.fill('0');
cout << y << '.';
cout.width(2); cout.fill('0');
cout << m << '.';
cout.width(2); cout.fill('0');
cout << d;
}
1020.
[풀이]
#include "iostream"
using namespace std;
int main(void) {
int front, rear;
char dash;
cin >> front >> dash >> rear;
cout.width(6); cout.fill('0');
cout << front;
cout.width(7); cout.fill('0');
cout << rear;
}
'PS' 카테고리의 다른 글
[코드업] c++ 100제 (1031 - 1040) (0) | 2024.01.31 |
---|---|
[코드업] c++ 100제 (1021 - 1030) (0) | 2024.01.31 |
[코드업] c++ 100제 (1001 - 1010) (0) | 2024.01.31 |
SWEA [D3] - 18662. 등차수열 만들기 (C언어) (0) | 2023.11.08 |
SWEA [D3] - 1206. [S/W 문제해결 기본] 1일차 - View (C언어) (0) | 2023.11.04 |