![[백준 / BOJ] 2741번 N 찍기 (C++, Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbJLdVV%2FbtrJgdPtKEH%2FhK4qTKkAtAC4dgdzdJtbO1%2Fimg.png)
[백준 / BOJ] 2741번 N 찍기 (C++, Python)◎ 자료구조와 알고리즘/백준(BOJ) 문제풀이2021. 8. 23. 00:13
Table of Contents
반응형
링크 : https://www.acmicpc.net/problem/2741
2741번: N 찍기
자연수 N이 주어졌을 때, 1부터 N까지 한 줄에 하나씩 출력하는 프로그램을 작성하시오.
www.acmicpc.net
문제

문제 풀이
순서대로 1부터 입력받은 N까지 출력해주면 되는 문제다!
C++ 코드 전문
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int main() | |
{ | |
std::ios_base::sync_with_stdio(false); | |
int val; | |
std::cin >> val; | |
for (int i = 1; i <= val; i++) | |
std::cout << i << "\n"; | |
return 0; | |
} |
Python 코드 전문
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val = int(input()) | |
for i in range(val): | |
print(i + 1) |
소감
이 문제에서 std::cin << std::endl;을 사용하면 시간 초과가 난다. 유의해야 하는 부분이다.
반응형
'◎ 자료구조와 알고리즘 > 백준(BOJ) 문제풀이' 카테고리의 다른 글
[백준 / BOJ] 11021번 A+B - 7 (C++, Python) (0) | 2021.08.23 |
---|---|
[백준 / BOJ] 2742번 기찍 N (C++, Python) (0) | 2021.08.23 |
[백준 / BOJ] 15552번 빠른 A+B (C++, Python) (0) | 2021.08.22 |
[백준 / BOJ] 8393번 합 (C++, Python) (0) | 2021.08.22 |
[백준 / BOJ] 10950번 A+B - 3 (C++, Python) (0) | 2021.08.22 |
@Reo :: 코드 아카이브
자기계발 블로그