Baekjoon 6550.ALL IN ALL(부분 문자열) c++ [Silver V]
·
Baekjoon/Silver
Contents풀이입력은 여러 개의 테스트 케이스s,t 10만을 넘지 않음 -> O(n)문자 하나씩 비교하면서 s가 완성되면 "Yes" 완성되지 못하면 "No"코드#include #include using namespace std;string is_subsequence(const string &s, const string &t){ int s_idx = 0, t_idx = 0; while (s_idx > s >> t) { cout
Baekjoon 2805.EKO(나무자르기) c++ [Silver II]
·
Baekjoon/Silver
이분탐색정렬된 범위에 특정 값을 찾거나 최적의 값을 구할 때 사용 left =0, right는 max로 설정 mid값을 잡아서 조건에 만족하는 최댓 값을 찾을 때까지 위해 반복#include #include #include using namespace std;typedef long long ll;int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int N, M; cin >> N >> M; vector trees(N); for (int i = 0; i > trees[i]; } int left = 0, right = *max_element(trees.begin(), tre..
Baekjoon 2003.수들의 합2 c++ [Silver IV]
·
Baekjoon/Silver
Two pointer 기법오른쪽으로 이동하면서 값을 더해 sum==M일 때 count를 올려주고, 해당 값이 M을 넘었을 때, left의 위치와 비교해서 지금까지 더해온 값을 모두 빼주며 sum을 초기화한다#include #include using namespace std;int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int N, M; cin >> N >> M; vector A(N); for (int i = 0; i > A[i]; } int left = 0, right = 0, sum = 0, count = 0; while (right M && left
Baekjoon 15650.N과 M (2) c++ [Silver III]
·
Baekjoon/Silver
#include #include using namespace std;void check(int N, int M, int start, vector &comb){ if (comb.size() == M) { for (int c : comb) cout > N >> M; vector combination; check(N, M, 1, combination); return 0;} 15652. N과 M(4)초기 숫자부터 다시 시작하도록 i+1에서 i로 바꾸면 된다#include #include using namespace std;void check(int N, int M, int start, vector &comb){ if (comb.size() == M..
Baekjoon 2775.부녀회장이 될테야 c++ [Bronze I]
·
Baekjoon/Bronze
#include #include using namespace std;int main(){ int T; cin >> T; while (T--) { int k, n; cin >> k >> n; vector apart(n + 1, 0); for (int i = 1; i
Baekjoon 10845.큐 c++ [Silver IV]
·
Baekjoon/Silver
#include #include #include using namespace std;int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int N; cin >> N; queue q; while (N--) { string command; cin >> command; if (command == "push") { int x; cin >> x; q.push(x); } else if (command == "pop") { ..