result[4] 칸 만들어서 삽입정렬하기 #include #include #include using namespace std; int main() { int arr[1000] = { 0 }; int n; cin >> n; for (int i = 0; i > arr[i]; } int result[4]; result[0] = arr[0]; for (int i = 1; i 2) y = 3; result[y] = arr[i]; for (int j = y; j > 0;j--) { //cout C언어/문제풀다 하나씩 2020.05.16
문자열을 숫자로/ 숫자를 문자열로 바꾸는 방법 문자열을 숫자로/ 숫자를 문자열로 바꾸는 방법 int num = 10; string str = to_string(num); num = stoi(str); C언어 2020.05.13
#include <algorithm>의 sort&compare함수 쓰기 - 사정정렬 #include 의 sort&compare함수 쓰기 bool compare string a string b 맨 마지막에 return false빼먹지 말기! 저거 빼먹어서 에러남 #include #include #include using namespace std; string t[20]; bool compare(string a, string b) { int lena = a.length(); int lenb = b.length(); if (lena lenb) return false; if (a > n; for (int i = 0;i < n;i++) .. C언어/문제풀다 하나씩 2020.05.13
#include <string> 두번째 기능 a+b = c #include #include using namespace std; int main(){ int n; cin >> n; string t[10]; for (int i = 0; i > t[i]; } int cnt = 0; for (int i = 0; i < n - 1;i++) { for (int j = i + 1;j < n;j++) { string c = t[i] + t[j]; if (c == "HITSMUSIC") { cnt++; } } } cout C언어/문제풀다 하나씩 2020.05.13
#include <string>은 놀라워! 비교 굿굿 #include #include using namespace std; string t[5]; void find() { for (int i = 0; i < 5;i++) { if (t[i] == "MAPOM") { cout t[i]; } for (int i = 0; i < 5;i++) { swap(t[i][1], t[i][3]); } find(); } t[i] = "MAPOM"처럼 바로 비교가능하고 swap도 가능 C언어/문제풀다 하나씩 2020.05.13
padding+바이트 문제 int char pointer 등 #include using namespace std; int data[10]; int main() { return 0; } int 는 4바이트 10개 있으니까 답은 40 #include using namespace std; double data[3]; char vect[10]; int dt[10]; int main() { return 0; } double 8 char 1 int 4 8*3 + 10 *1 + 10 *4 = 74; 답은 74 padding 포함 #include using namespace std; struct Node { int x; char t; }; Node vect[100]; int main() { return 0; } struct 같은 구조체는 네모나게 잘린다고 했음 int 4 cha.. C언어/문제풀다 하나씩 2020.05.13
vector 사용해서 풀어보는 sliding window 최소합 구하기 입력 예제 9 7 2 4 3 2 1 1 9 2 출력 결과 7 #include #include using namespace std; vectorarr; int main() { int n; cin >> n; for (int i = 0;i > temp; arr.push_back(temp); } int sum = arr[0] + arr[1] + arr[2] + arr[3]; int min = sum; for (int i = 0; i sum) { min = sum; } } cout C언어/문제풀다 하나씩 2020.05.13
시간복잡도 계산해보기! 민철이가 짠 네 개의 소스코드를 읽어보고, 시간복잡도를 기준으로 채점 해 주세요. 빠른 알고리즘일수록 점수가 높습니다. 문제 번호를 입력하면, 그 문제의 점수를 출력 해 주세요. O(N^3) = 1 점 O(N^2) = 2 점 O(N log N) = 10 점 O(N) = 11점 O(log N) = 20점 O(1) = 21점 1번 소스코드 #include using namespace std; int main() { for (int i = 0; i n; for (int y = 0; y n; for (int y = 0; y < n; y++) { for (int x = 0; x < 5; x++) { for (int .. C언어/문제풀다 하나씩 2020.05.13
DFS 간단 코드 다시 한번더! string으로 이름 불러오기 심화반 가기 전에 마지막으로 하는 DFS 재귀코드 #include using namespace std; string t[3]; int who[3]; void abc(int lev) { if (lev == 3) { for (int i = 0; i < lev;i++) { cout C언어/문제풀다 하나씩 2020.05.13
가장 큰 숫자값 3개 구하기 // 4칸짜리 삽입정렬 이용함 입력 예제 3 4 1 5 2 7 1 5 1 6 3 3 2 4 출력 결과 7(0,3) 6(1,3) 5(0,1) #1 for (int i = 0; i 0;k--) { if (result[k - 1] > arr[i][j]; } } for (int i = 0; i < y;i++) { for (int j.. C언어/문제풀다 하나씩 2020.05.13