# 생각

cout.width();

cout.fill();

사용하여 원하는 길이로 출력할 수 있다

 

 

# 전체 코드

#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n1, n2, n3;
	char c1, c2;
	cin >> n1 >> c1 >> n2 >> c2 >> n3;
	cout.width(4);
	cout.fill('0');
	cout << n1 << c1;
	cout.width(2);
	cout.fill('0');
	cout << n2 << c2;
	cout.width(2);
	cout.fill('0');
	cout << n3;
}

https://codeup.kr/problem.php?id=1019 

 

[기초-입출력] 연월일 입력받아 그대로 출력하기

C언어기초100제v1.2 : @컴퓨터과학사랑, 전국 정보(컴퓨터)교사 커뮤니티/연구회 - 학교 정보(컴퓨터)선생님들과 함께 수업/방과후학습/동아리활동 등을 통해 재미있게 배워보세요.  - 모든 내용

codeup.kr

+ Recent posts