# 생각

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 c;
	cin >> n1 >> c >> n2 >> c >> n3;
	c = '-';
	cout.width(2);
	cout.fill('0');
	cout << n3 << c;
	
	cout.width(2);
	cout.fill('0');
	cout << n2 << c;

	cout.width(4);
	cout.fill('0');
	cout << n1;
}

 


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

 

[기초-입출력] 년월일 입력 받아 형식 바꿔 출력하기(설명)

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

codeup.kr

 

+ Recent posts