Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
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
31
Archives
Today
Total
관리 메뉴

코딩로그

[백준/BOJ/C++] 11944번 NN 본문

YJ/C++

[백준/BOJ/C++] 11944번 NN

Team DAON 2021. 11. 12. 15:36

[문제]

문제는 매우 간단하다. N을 N번 출력하는 프로그램을 작성하여라. 다만, 답이 길어지는 경우 답의 앞 M자리만 출력한다.

[입력]

첫 번째 줄에는 N, M이 주어진다. (1 ≤ N, M ≤ 2016)

[출력]

N을 N번 출력한다. 만약 답이 길어지면 답의 앞 M자리를 출력한다.

[Source Code]

#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	string input;
	int num, count = 0;
	cin >> input >> num;

	if(input.length() * stoi(input) >= num){
		for(int i = 0; i < num; i++){
			if(count == input.length())
				count = 0;
		
			cout << input[count++];
		}
	}
	else{
		for(int i = 0; i < stoi(input); i++){
			cout << input;
		}
	}
	
}

[결과 화면]