728x90
4470번: 줄번호
텍스트에서 줄을 입력받은 뒤, 줄 번호를 출력하는 프로그램을 작성하시오.
www.acmicpc.net
문제 풀이
입력값을 받아, 번호를 붙여 순서대로 출력시켜준다.
정답 코드
C++
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define ll long long
int main() {
fast;
string N, s;
getline(cin, N);
for (int i = 1; i <= stoi(N); i++) {
getline(cin, s);
cout << i << ". " << s << "\n";
}
}
python
for i in range(1, int(input()) + 1) :
print(str(i) + ". " + input())
728x90
'Algorithm > PS' 카테고리의 다른 글
[BOJ/백준] 5300 - Fill the Rowboats! [C++/python] (0) | 2023.03.02 |
---|---|
[BOJ/백준] 4589 - Gnome Sequencing [C++/python] (0) | 2023.03.01 |
[BOJ/백준] 3765 - Celebrity jeopardy [C++/python] (0) | 2023.03.01 |
[C++, python] BOJ, 백준 3733 - Shares (0) | 2023.02.28 |
[C++, python] BOJ, 백준 2083 - 럭비 클럽 (0) | 2023.02.28 |