알고리즘 연습

    [이것이 취업을 위한 코딩테스트다] 그리디 알고리즘

    알고리즘을 공부하기 위해 책을 구매했다. 파이썬을 공부하는것 보다 현재 내 직무에 맞는 언어가 C++이기에 깃허브의 코드를 참고하여 연습하고 있다. 큰수의 법칙 (92p) #include #include #include int main() { std::ios_base::sync_with_stdio(); std::cin.tie(0); std::cout.tie(0); int n, m, k; std::vector v; std::cin >> n >> m >> k; for (int i = 0; i > x; v.push_back(x);//vector 끝에 요소 추가 } sort(v.begin(), v.end()); int first = v[n - 1]; int s..

    파이썬 날짜 출력

    import datetime print(str(datetime.datetime.now())[:10])

    코드업 6092 [기초-리스트] 이상한 출석 번호 부르기1

    n = int(input()) a = input().split() for i in range(n): # a에 split으로 입력된 값들을ㅌ a[i] = int(a[i]) # a[0]~a[n-1]에 할당 d = [] for i in range(24): # 리스트 d에 24개까지 0으로 할당 d.append(0) for i in range(n): # 불려진 숫자를 d의 a번의 학생이 불릴때마다 카운트한다. d[a[i]] += 1 for i in range(1,24): print(d[i], end=' ') 역순으로 출력하기 코드 퀄리티 보소 n = int(input()) k = list(map(int, input().split())) for i in range(n-1,-1,-1): print(k[i], end..

    C++ 2442 별찍기 5

    #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i

    C++ 10984 내학점을 구해줘

    #include #include using namespace std; int main() { ios_base::sync_with_stdio(); cin.tie(); cout.tie(); int n; cin >> n; while (n--) { int num; cin >> num; vectorgrade(num); int sum = 0; float avg = 0; for (int i = 0; i > grade[i].first >> grade[i].second; for (int i = 0; i < num; i++) { sum += grade[i].first; avg += grade[i].first * grade[i].second; } cout

    C++11098 첼시를 도와줘

    #include #include ; #include ; using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; while (n--) { int t; cin >> t; int max = 0; vector c(t); string maxName; for (int i = 0; i > c[i].first >> c[i].second; if (max < c[i].first) { max = c[i].first; maxName = c[i].second; } } cout

    C++ 1977 완전제곱수

    #include #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int m, n; cin >> m >> n; int arr[10000] = { 0 }; int sum = 0; int min = 10000; for (int i = 1; i < n; i++) { arr[i] = i * i; } for (int i = 1; i

    C++ 1541 잃어버린 괄호

    #include #include using namespace std; int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); string str; string tmp = ""; int res = 0; bool minus = false;//빼기 확인용 cin >> str; for (int i = 0; i

    C++ 1931 회의실 배정

    문제를 이해하는것도 한참걸렸다. #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); int n; cin >> n; vectortime(n); int savetime = 0; int cnt = 0; for (int i = 0; i > time[i].second >> time[i].first; sort(time.begin(), time.end()); for (int i = 0; i < n; i++) { if (savetime

    C++ 11047 동전0 (그리디알고리즘)

    #include #include #include using namespace std; int main() { int n, k; cin >> n >> k; vectorcoin(n); int cnt = 0; for (int i = 0; i > coin[i]; } sort(coin.begin(), coin.end(), greater()); for (int i = 0; i = 0) { cnt++; k -= coin[i]; } } cout

    C++ 11650 좌표 정렬하기

    #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vectorarr(n, vector(2, 0)); for (int i = 0; i > arr[i][0]; cin >> arr[i][1]; } sort(arr.begin(), arr.end()); for (int i = 0; i < arr.size(); i++) { cout

    C++ 1427 소트 인사이드

    #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string strNum; cin >> strNum; sort(strNum.begin(), strNum.end(), greater()); cout

    C++ 2231 분해합

    #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int min = n; for (int i = 0; i n; for (int i = 1; i

    C++ 2798 블랙잭

    #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; int* arr = new int[n]; int max=0; for (int i = 0;i > arr[i]; } for (int i = 0;i < n;i++) { for (int j = i+1; j < n;j++) { for (int k = j+1; k < n; k++) { if (i != j || j != k || k != i) { int sum = arr[i] + arr[j] + arr[k]; if (sum

    C++ 4153 직각삼각형

    #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int x, y, z; while (1) { cin >> x >> y >> z; int temp = 0; if (x == 0 || y == 0 || z == 0) break; if (x > y) { temp = x; x = y; y = temp; } if (y > z) { temp = y; y = z; z = temp; } if (z * z == x * x + y * y) { cout

    C++1085 직사각형에서 탈출

    #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int x, y, w, h; cin >> x >> y >> w >> h; int xmin = 0; int ymin = 0; int totalmin = 0; (x) > (w - x) ? xmin = w - x : xmin = x; (y) > (h - y) ? ymin = h - y : ymin = y; xmin > ymin ? totalmin = ymin : totalmin = xmin; cout

    C++ 9020 골드바흐의 추측

    #include #include using namespace std; bool isPrime(int i) {//소수면 true를 반환함. int rt; rt = sqrt(i); if (rt == 1 && i != 1) return true; if (i % 2) { for (int j = 2; j > t; while (t--) { int n; cin >> n; for (int i = n / 2; i >= 2;i--) { if (isPrime(i) && isPrime(n - i)) { cout

    C++ 4948 베르트랑 공준

    #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int cnt = 0; int res = 0; for (int i = n+1; i

    C++ 11653 소인수분해

    #include using namespace std; int main() { //소인수분해 int n; cin >> n; while (n!=1) { for (int i = 2;i

    C++ 2581 소수

    #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int m, n; cin >>m >> n; int cnt = 0; int max=0; int min = -1; for (int i = m;i

    C++ 피보나치 수열

    #include using namespace std; int fib(int num) { if (num == 0) return 0; else if (num == 1) return 1; else return fib(num - 1) + fib(num - 2); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; cout

    C++ 2839 설탕배달

    #include using namespace std; int main() { int n; cin >> n; int head = n / 5; int mod, res; while (head >= 0) { mod = 0; res = 0; if (head > 0) { mod = n - 5 * head; res = head; } else mod = n; res += mod / 3; mod = mod % 3; if (mod == 0) { cout

    C++ 2292 벌집

    #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int layer = 1; int room = 1; int roomN; cin >> roomN; while (roomN > room) { layer++; room += 6 * (layer - 1); } cout

    C++ 2908 상수

    #include #include #include using namespace std; int main() { string a, b; cin >> a >> b; reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); cout b ? a : b); } 아으.. reverse로 푸는 걸 까먹어서 두 번째 풀어도 헤맸다. 외우자.

    C++ 1157 단어공부

    #include #include #include using namespace std; int main() { string word; cin >> word; int point; int max = 0; int cnt = 0; int arr[26] = { 0 }; transform(word.begin(), word.end(), word.begin(), (int(*)(int))toupper); for (int i = 0; i max) { max = arr[i]; cnt = 0; point = i; } if (max == arr[i]) cnt++; } i..

    C++ 1152 단어의 개수

    #include #include using namespace std; int main() { string s; getline(cin, s); int cnt = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == ' ') { cnt++; } } if (s[0] == ' ') { cnt--; } if (s[s.size()-1] == ' ') { cnt--; } cout

    C++ 2675 문자열 반복

    #include #include using namespace std; int main() { int t; cin >> t; while (t--) { int r; cin >> r; string s; cin >> s; for (int i = 0; i < s.size(); i++) { for (int j = 0; j < r; j++) { cout

    C++ 10809 알파벳 찾기

    #include #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); string str; string alphabet = "abcdefghijklmnopqrstuvwxyz"; cin >> str; for (int i = 0; i < alphabet.size(); i++) { cout

    C++ 1065 한수

    #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int n; cin>> n; int hs = 0; for (int i = 1; i =100) if (i / 100 - i % 100 / 10 == i % 100 / 10 - i % 10) { hs++; } } cout

    백준 14681 C++ 사분면

    #include using namespace std; int main() { int a, b; cin >> a >> b; if (a > 0 && b > 0) cout 0) cout