C++/Baekjoon
백준 2742: 기찍 N
RIsN
2022. 7. 18. 21:14
문제
자연수 N이 주어졌을 때, N부터 1까지 한 줄에 하나씩 출력하는 프로그램을 작성하시오.
입력
첫째 줄에 100,000보다 작거나 같은 자연수 N이 주어진다.
출력
첫째 줄부터 N번째 줄 까지 차례대로 출력한다.
코드
#include <iostream>
using namespace std;
int main()
{
// :: 입력
int count;
cin >> count;
// :: 연산
string textContainer = "";
for(int index = count; index >= 1; index--) {
// :: 연산
textContainer += to_string(index);
// :: 개행 확인
if(index != 1) textContainer += "\n";
}
// :: 출력
cout << textContainer;
return 0;
}