[Java] 백준 15단계 - 1735번 문제 (분수 합)
자료구조 & 알고리즘/BOJ2023. 7. 26. 04:26[Java] 백준 15단계 - 1735번 문제 (분수 합)

문제설명 소스코드 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int arr[] = new int[4]; for(int i = 0; i < 4; ++i) arr[i] = in.nextInt(); int a = (arr[0] * arr[3]) + (arr[1]* arr[2]); int b = arr[1] * arr[3]; int minDivisor = gcd(a, b); System.out.println(a / minDivisor + " " + b / minDivisor); } public static int gcd(int a, i..

[Java] 백준 15단계 - 13241번 문제 (최소공배수)
자료구조 & 알고리즘/BOJ2023. 7. 26. 03:40[Java] 백준 15단계 - 13241번 문제 (최소공배수)

문제설명 소스코드 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); long a = in.nextLong(); long b = in.nextLong(); System.out.println(a * b / gcd(a, b)); } public static long gcd(Long a, Long b) { if(b == 0) return a; else return gcd(b, a % b); } } 설명 최소공배수와 최대공약수와의 관계는 아래와 같다. 두 자연수의 곱 = 최대공약수 × 최소공배수 최소공배수 = 두 자연수의 곱 / 최대공약수 유클..

[Java] 백준 15단계 - 1934번 문제 (최소공배수)
자료구조 & 알고리즘/BOJ2023. 7. 25. 19:31[Java] 백준 15단계 - 1934번 문제 (최소공배수)

문제설명 소스코드 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); for(int i = 0; i < T; i++) { int a = in.nextInt(); int b = in.nextInt(); System.out.println(a * b / gcd(a, b)); } } public static int gcd(int a, int b) { if(b == 0) return a; else return gcd(b, a % b); } } 설명 최소공배수와 최대공약수와의 관계는 아래와 같다. 두 자연수의..

[C++] 백준 14단계 - 11478번 문제 (서로 다른 부분 문자열의 개수)
자료구조 & 알고리즘/BOJ2023. 7. 24. 07:42[C++] 백준 14단계 - 11478번 문제 (서로 다른 부분 문자열의 개수)

문제설명 소스코드 #include #include #include using namespace std; int main() { string input; int count = 0; cin >> input; for (int i = 0; i < input.length(); ++i) { vector vec; for (int j = 0; j < input.length() - i; ++j) { string strTmp = input.substr(j, i + 1); //문자열 잘라내기 vec.push_back(strTmp); //벡터에 원소 추가 } sort(vec.begin(), vec.end()); //벡터 정렬 vec.erase(unique(vec.begin(), vec.end()), vec.end()); //..

[C++] 백준 14단계 - 1269번 문제 (대칭 차집합)
자료구조 & 알고리즘/BOJ2023. 7. 24. 03:54[C++] 백준 14단계 - 1269번 문제 (대칭 차집합)

문제설명 소스코드 map을 이용 #include #include using namespace std; int main(void) { map m; int aSize, bSize; cin >> aSize >> bSize; for (int i = 0; i > input; m.insert(pair(input, true)); //입력받은 값과 true를 맵에 저장 } int count = 0; //교집합 개수를 저장 for (int i = 0; i > input; if (m[input] == true) count++; //맵에 해당하는 값이 있으면 count를 1증가 } cout > aSize >> ..

[C++] 백준 14단계 1764번 문제 (듣보잡)
자료구조 & 알고리즘/BOJ2023. 7. 23. 21:07[C++] 백준 14단계 1764번 문제 (듣보잡)

문제설명 소스코드 #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); //표준 스트림 동기화 해제 cin.tie(0); //입출력 연결 끊기 vectorv1, v2; int N, M; cin >> N >> M; for (int i = 0; i > input; v1.push_back(input); } sort(v1.begin(), v1.end()); //v1 정렬 for (int i = 0; i > input; if (binary_search(v1.begin(), v1.end(),..

[C++] 백준 14단계 - 10816번 문제 (숫자 카드 2)
자료구조 & 알고리즘/BOJ2023. 7. 22. 09:35[C++] 백준 14단계 - 10816번 문제 (숫자 카드 2)

문제설명 소스코드 #include #include using namespace std; int main(void) { ios_base::sync_with_stdio(false); //표준 스트림 동기화 해제 cin.tie(nullptr); //입출력 연결 끊기 map m; int N, M; cin >> N; for (int i = 0; i > input; ++m[input]; } cin >> M; for (int i = 0; i > input; cout

[C++] 백준 14단계 - 14425번 문제 (문자열 집합)
자료구조 & 알고리즘/BOJ2023. 7. 21. 19:27[C++] 백준 14단계 - 14425번 문제 (문자열 집합)

문제설명 소스코드 #include #include using namespace std; int main(void) { map m; int N, M; int count = 0; cin >> N >> M; for (int i = 0; i > str; m.insert(pair(str, true)); } for (int i = 0; i > str; if (m[str] == true) count++; } cout

image