[백준] 10872: 팩토리얼
2020. 12. 29. 05:39
Problem set
10872번: 팩토리얼 0보다 크거나 같은 정수 N이 주어진다. 이때, N!을 출력하는 프로그램을 작성하시오. www.acmicpc.net #include #include using namespace std; unsigned int facto(int n) { if (n == 1 || n == 0) { return 1; } return n * facto(n - 1); } auto main()->int { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int N; cin >> N; cout
[백준] 10870: 피보나치 수 5
2020. 12. 29. 05:37
Problem set
10870번: 피보나치 수 5 피보나치 수는 0과 1로 시작한다. 0번째 피보나치 수는 0이고, 1번째 피보나치 수는 1이다. 그 다음 2번째 부터는 바로 앞 두 피보나치 수의 합이 된다. 이를 식으로 써보면 Fn = Fn-1 + Fn-2 (n ≥ 2)가 www.acmicpc.net #include #include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); function fib = [&fib](const int n){ if(n ==0){return 0;} return n > num; cout
[백준] 10866: 덱
2020. 12. 29. 05:36
Problem set
10866번: 덱 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net #include #include #include int main() { using namespace std; ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t; cin >> t; deque dq; while (t--) { string cmd; cin >> cmd; if (cmd == "push_front") { int n; cin >> n; dq.push_fro..
[백준] 10845: 큐
2020. 12. 29. 05:34
Problem set
10845번: 큐 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net #include #include template struct Queue { T data[10000]; int begin, end; Queue() : begin(0), end(0) {} void push(int num) { if (empty()) { data[begin] = num; end++; } else { data[end++] = num; } } int pop() { if (empty()) { return -1; } return data[beg..
[백준] 10844: 쉬운 계단 수
2020. 12. 29. 05:33
Problem set
10844번: 쉬운 계단 수 첫째 줄에 정답을 1,000,000,000으로 나눈 나머지를 출력한다. www.acmicpc.net #include using namespace std; long long d[101][10]; long long mod = 1000000000; auto main()->int { int n; cin >> n; for (int i = 1; i
[백준] 10828: 스택
2020. 12. 29. 05:32
Problem set
10828번: 스택 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net #include #include #include int main() { using namespace std; ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; stack s; while (n--) { string cmd; cin >> cmd; if (cmd == "push") { int num; cin >> num; s.push(num); ..
[백준] 10818: 최소, 최대
2020. 12. 29. 05:30
Problem set
10818번: 최소, 최대 첫째 줄에 정수의 개수 N (1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄에는 N개의 정수를 공백으로 구분해서 주어진다. 모든 정수는 -1,000,000보다 크거나 같고, 1,000,000보다 작거나 같은 정수이다. www.acmicpc.net #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); size_t sz; cin >> sz; vector vec; vec.resize(sz); for (size_t i = 0; i > vec[i]; } int min=vec[0], m..
[백준] 10799: 쇠막대기
2020. 12. 29. 05:27
Problem set
10799번: 쇠막대기 여러 개의 쇠막대기를 레이저로 절단하려고 한다. 효율적인 작업을 위해서 쇠막대기를 아래에서 위로 겹쳐 놓고, 레이저를 위에서 수직으로 발사하여 쇠막대기들을 자른다. 쇠막대기와 레이저 www.acmicpc.net #include #include #include using namespace std; int main() { string a; cin >> a; int n = a.size(); stack s; int ans = 0; for (int i=0; i