목록C++/BAEKJOON (C++) (17)
천천히 빛나는
문제 풀이 전, 2차원 배열 동적할당 방법을 소개하도록 하겠다. 행이 n, 열이 m인 2차원 배열이다. int n, m; cin >> n >> m; int** arr = new int* [n]; for (int i = 0; i < m; i++) { arr[i] = new int[m]; } 자바에서 소개했던 2차원 배열 모습인데 이렇게 생각하면 된다. 2738. N*M크기의 두 행렬 A와 B가 주어졌을 때, 두 행렬을 더하는 프로그램을 작성하시오. #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; int arr1[101][101] = {0}; int arr2[101][101..
25083. 아래 예제와 같이 새싹을 출력하시오. #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout > num; piece[i] -= num; } for (int i = 0; i < 6; i++) { cout n; for (int i = 1; i str; for (int j = 0; j < str.length(); j++) { int last = j; for (int k = j+1; k < str.length(); k++) { if (str[j] == str[k]) { if (last != k - 1) { group = 0; break; } else { last = k; } } } if (grou..
27866. 단어 S와 정수 i가 주어졌을 때, S의 i번째 글자를 출력하는 프로그램을 작성하시오. #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; int i; cin >> s >> i; cout > s; cout > t; for (int i = 0; i > s; cout n; char* c = new char[n+1]; cin >> c; int sum = 0; for (int i = 0; i < n; i++) { sum += int(c[i]) - '0'; } cout s; int n = s.length(); int location[26];..
10807. 총 N개의 정수가 주어졌을 때, 정수 v가 몇 개인지 구하는 프로그램을 작성하시오. #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, v; cin >> n; int* arr = new int[n]; for (int i = 0; i > arr[i]; } cin >> v; int count = 0; for (int i = 0; i n >> x; int* a = new int[n]; for (int i = 0; i > a[i]; } fo..
10950. 두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오. #include using namespace std; int main() { int n; cin >> n; for (int i = 1; i > n; int item, price, total = 0; for (int i = 0; i > item >> price; total += item * price; } if (x == total){ cout b; cout b) { ... } 위와 같은 방식도 가능하다. cin이 조건문 안에 있는 경우에 연산자 오버로딩에 의해 bool..
1330. 두 정수 A와 B가 주어졌을 때, A와 B를 비교하는 프로그램을 작성하시오. #include using namespace std; int main() { int a, b; cin >> a >> b; if (a > b) { cout = 90) { cout = 80) { cout = 70) { cout = 60) { cout year; if ((year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0))) { cout x >> y; if ((x > 0) && (y > 0)) { cout c; a += c / 60; b += c % 60; if (b >= 60) { b -= 60; a += 1; } if (a >= 24) { a -= 24; } cout ..
2557. Hello World!를 출력하시오. #include using namespace std; int main(){ cout A >> B; cout > a >> b;와 같이 계속해서 입력을 받을 수 있다. 1001. 두 정수 A와 B를 입력받은 다음, A-B를 출력하는 프로그램을 작성하시오. #include using namespace std; int main(){ int A, B; cin >> A >> B; cout > A >> B; cout > A >> B; cout > B; cout