티스토리 뷰
입력받은 연, 월, 일을 yyyy.mm.dd 형식으로 출력한다.
(%02d를 사용하면 2칸을 사용해 출력하는데, 한 자리 수인 경우 앞에 0을 붙여 출력한다.)
이렇게 비효율적으로 푸는게 맞는지 모르겠다. 분명 적합한 함수가 있을텐데..
C 가 굉장히 다 짜야하는 비효율적인 언어라고 생각했는데,,, C++ 아직 낯설다 ㅠ
cout.width : 출력 자릿수 설정
cout.fill() : 출력 자릿수를 맞추고 빈 자리를 무엇으로 채울건지
#include<iostream>
using namespace std;
int main() {
int y, m, d;
cin >> y;
cin.ignore(256, '.');
cin >> m;
cin.ignore(256, '.');
cin >> 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 << endl;
}
'알고리즘 > C++' 카테고리의 다른 글
C++ 정수, 소수점 분할 modf, cmath (0) | 2020.02.15 |
---|---|
c++ cin.get cin.getline 차이 (0) | 2020.02.15 |
코드업 기초 100제 : 1021 C++ 단어 출력 cin.getline() (0) | 2020.02.15 |
코드업 기초 100제 : 1018 C++ (cin.ignore) (0) | 2020.02.15 |
코드업 기초 100제 : 소수점 출력 관련 함수 fixed, precsion (0) | 2020.02.15 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 웹 배포
- CellForRowAt 호출안됨
- pythonanywhere배포방법
- Firebase 데이터베이스 추천
- 장고 태그달기
- django tag
- iOS 검은 화면
- django 로그인접근
- cleaned_data
- 데이터베이스 추천
- django clean
- Realtime Database
- 알파벳 카운팅
- iOS UITableView 출력안됨
- django 개발일지
- iOS 데이터베이스
- Django
- CellForRowAt Not Called
- UITableViewController Not Working
- django 태그
- 장고 게시판
- ModelForm Form 차이
- pythonanywhere배포
- 까만 화면
- 테이블출력안됨
- iOS 화면 안나옴
- django pythoneverywhere
- 실시간 데이터베이스
- python 웹 배포
- django 게시판
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 28 |
29 | 30 |
글 보관함