├── .gitignore ├── Baekjoon ├── 1002.cpp ├── 10026.cpp ├── 1003.c ├── 10039.c ├── 1005.cpp ├── 1008.c ├── 1009.cpp ├── 10093.cpp ├── 1010.cpp ├── 10103.cpp ├── 1012.cpp ├── 1015.cpp ├── 1016.cpp ├── 10162.cpp ├── 10164.cpp ├── 10171.c ├── 10172.c ├── 10178.cpp ├── 1018.cpp ├── 1021.cpp ├── 10211.cpp ├── 1026.cpp ├── 10282.cpp ├── 10340.c ├── 1037.cpp ├── 1043.cpp ├── 10474.cpp ├── 1051.cpp ├── 10531.cpp ├── 10569.cpp ├── 1067.cpp ├── 1068.cpp ├── 10718.c ├── 1074.cpp ├── 1075.cpp ├── 10757.c ├── 1076.cpp ├── 10768.c ├── 10773.cpp ├── 10775.cpp ├── 10797.cpp ├── 10799.cpp ├── 10804.cpp ├── 10807.cpp ├── 10808.cpp ├── 10809.cpp ├── 10811.cpp ├── 10814.cpp ├── 10815.cpp ├── 10816.cpp ├── 10817.c ├── 10818.c ├── 10819.cpp ├── 10820.c ├── 10824.cpp ├── 10825.cpp ├── 10828.cpp ├── 10830.cpp ├── 10844.c ├── 10845.cpp ├── 1085.cpp ├── 10854.cpp ├── 10866.cpp ├── 10867.cpp ├── 10868.cpp ├── 10869.c ├── 10870.c ├── 10871.cpp ├── 10872.cpp ├── 10886.cpp ├── 10903.cpp ├── 10926.c ├── 10930.py ├── 10932.py ├── 1094.cpp ├── 10950.c ├── 10951.c ├── 10952.c ├── 10953.c ├── 10986.cpp ├── 10987.cpp ├── 10988.c ├── 10989.cpp ├── 10990.c ├── 10991.c ├── 10992.c ├── 10995.cpp ├── 10996.cpp ├── 10998.c ├── 10999.cpp ├── 1100.cpp ├── 11003.cpp ├── 11004.cpp ├── 11021.c ├── 11022.c ├── 11047.cpp ├── 11048.cpp ├── 11049.cpp ├── 11050.cpp ├── 11051.cpp ├── 11052.cpp ├── 11053.cpp ├── 11054.cpp ├── 11055.cpp ├── 11057.cpp ├── 11060.cpp ├── 11066.cpp ├── 1110.cpp ├── 11123.cpp ├── 1120.cpp ├── 11238.cpp ├── 11279.cpp ├── 11297.cpp ├── 11328.cpp ├── 11365.cpp ├── 1138.cpp ├── 11383.cpp ├── 11402.cpp ├── 11403.cpp ├── 11404.cpp ├── 11438.cpp ├── 11440.cpp ├── 11441.cpp ├── 11442.cpp ├── 11443.cpp ├── 11444.cpp ├── 1145.cpp ├── 11478.cpp ├── 1149.cpp ├── 11505.cpp ├── 1152.cpp ├── 11559.cpp ├── 1157.cpp ├── 11575.cpp ├── 1158.cpp ├── 11586.cpp ├── 1159.cpp ├── 1160.cpp ├── 11650.cpp ├── 11651.cpp ├── 11652.cpp ├── 11653.cpp ├── 11654.cpp ├── 11655.cpp ├── 11656.cpp ├── 11659.cpp ├── 11660.cpp ├── 1167.cpp ├── 11689.cpp ├── 11718.cpp ├── 11719.cpp ├── 11720.c ├── 11721.c ├── 11722.cpp ├── 11724.cpp ├── 11725.cpp ├── 11726.cpp ├── 11727.c ├── 11728.c ├── 11729.cpp ├── 11758.cpp ├── 11778.cpp ├── 11779.cpp ├── 11780.cpp ├── 1181.cpp ├── 11819.cpp ├── 1182.cpp ├── 1193.cpp ├── 11931.cpp ├── 11944.cpp ├── 11945.cpp ├── 11966.cpp ├── 11967.cpp ├── 1197.cpp ├── 12008.cpp ├── 12015.cpp ├── 12100.cpp ├── 1212.cpp ├── 1225.c ├── 1237.c ├── 1238.cpp ├── 1247.cpp ├── 1253.cpp ├── 1259.cpp ├── 1260.cpp ├── 1261.cpp ├── 1264.cpp ├── 1267.c ├── 1268.cpp ├── 1269.cpp ├── 12727.cpp ├── 12728.cpp ├── 12738.cpp ├── 1275.cpp ├── 12837.cpp ├── 12844.cpp ├── 12849.cpp ├── 12850.cpp ├── 12852.cpp ├── 12865.cpp ├── 12916.cpp ├── 1292.cpp ├── 12925.cpp ├── 1296.cpp ├── 1300.cpp ├── 1302.cpp ├── 1305.cpp ├── 1306.cpp ├── 1309.cpp ├── 13150.cpp ├── 13163.cpp ├── 13211.cpp ├── 1322.cpp ├── 13225.c ├── 13241.cpp ├── 13246.cpp ├── 1325.cpp ├── 1330.c ├── 1331.cpp ├── 13330.c ├── 13412.cpp ├── 13456.cpp ├── 13458.cpp ├── 13460.cpp ├── 13463.cpp ├── 13511.cpp ├── 13549.cpp ├── 1357.cpp ├── 13610.cpp ├── 13618.cpp ├── 13701.cpp ├── 13752.cpp ├── 1389.cpp ├── 13913.cpp ├── 13926.cpp ├── 1395.cpp ├── 13977.cpp ├── 13985.cpp ├── 14002.cpp ├── 1406.cpp ├── 14245.cpp ├── 14264.cpp ├── 1427.cpp ├── 14289.cpp ├── 1431.cpp ├── 14425.cpp ├── 14427.cpp ├── 14428.cpp ├── 14438.cpp ├── 14499.cpp ├── 14501.cpp ├── 14502.cpp ├── 14503.cpp ├── 1456.cpp ├── 14565.cpp ├── 14567.cpp ├── 14579.cpp ├── 14588.cpp ├── 14589.cpp ├── 1463.cpp ├── 14681.cpp ├── 14696.cpp ├── 1475.cpp ├── 1476.cpp ├── 1485.cpp ├── 14888.cpp ├── 14889.c ├── 14890.cpp ├── 14891.cpp ├── 14909.c ├── 14918.cpp ├── 14921.cpp ├── 14942.cpp ├── 1495.cpp ├── 14958.cpp ├── 1500.cpp ├── 1504.cpp ├── 1516.cpp ├── 1520.cpp ├── 1533.cpp ├── 15340.cpp ├── 15353.c ├── 1541.cpp ├── 1543.cpp ├── 15439.cpp ├── 1546.cpp ├── 1547.c ├── 1550.cpp ├── 15552.cpp ├── 15596.c ├── 15624.cpp ├── 1563.cpp ├── 15638.cpp ├── 15649.cpp ├── 15650.cpp ├── 15651.cpp ├── 15652.cpp ├── 15654.cpp ├── 15655.cpp ├── 15656.cpp ├── 15657.cpp ├── 15663.cpp ├── 15664.cpp ├── 15665.cpp ├── 15666.cpp ├── 15683.cpp ├── 15685.cpp ├── 15686.cpp ├── 15688.cpp ├── 15712.cpp ├── 15727.cpp ├── 15736.cpp ├── 15824.cpp ├── 15829.cpp ├── 15873.cpp ├── 15894.c ├── 15964.cpp ├── 15965.cpp ├── 15969.cpp ├── 15988.cpp ├── 1600.cpp ├── 16120.cpp ├── 16134.cpp ├── 16172.cpp ├── 1620.cpp ├── 16234.cpp ├── 16236.cpp ├── 1629.cpp ├── 16396.cpp ├── 16430.cpp ├── 1644.cpp ├── 1647.cpp ├── 16480.c ├── 16505.cpp ├── 16507.cpp ├── 16561.cpp ├── 16563.cpp ├── 16570.cpp ├── 1676.cpp ├── 16940.cpp ├── 16948.cpp ├── 1697.cpp ├── 16975.cpp ├── 1699.cpp ├── 17009.cpp ├── 1701.cpp ├── 17069.cpp ├── 1707.cpp ├── 17070.cpp ├── 1708.cpp ├── 17118.rb ├── 1712.cpp ├── 17134.cpp ├── 17140.cpp ├── 17141.cpp ├── 17142.cpp ├── 17144.cpp ├── 1717.cpp ├── 17173.cpp ├── 1718.cpp ├── 1719.cpp ├── 17206.cpp ├── 1722.cpp ├── 17244.cpp ├── 1725.cpp ├── 17252.cpp ├── 17253.cpp ├── 17281.cpp ├── 17293.cpp ├── 1735.cpp ├── 17390.cpp ├── 1740.cpp ├── 17401.cpp ├── 17404.cpp ├── 17435.cpp ├── 1744.cpp ├── 17466.cpp ├── 1747.cpp ├── 17471.cpp ├── 17472.cpp ├── 17478.cpp ├── 1753.cpp ├── 1759.cpp ├── 1761.cpp ├── 1764.cpp ├── 1766.cpp ├── 17779.cpp ├── 1780.cpp ├── 17822.cpp ├── 17836.cpp ├── 1786.cpp ├── 1789.cpp ├── 1799.cpp ├── 18017.cpp ├── 1816.cpp ├── 1822.cpp ├── 18223.cpp ├── 18258.cpp ├── 18408.cpp ├── 18436.cpp ├── 1874.cpp ├── 18783.cpp ├── 18787.cpp ├── 1890.cpp ├── 18917.cpp ├── 1904.cpp ├── 1912.c ├── 1914.cpp ├── 1915.cpp ├── 1916.cpp ├── 1918.cpp ├── 1919.c ├── 1920.cpp ├── 1922.cpp ├── 1924.cpp ├── 1926.cpp ├── 1927.cpp ├── 1929.cpp ├── 1931.cpp ├── 1932.cpp ├── 1934.c ├── 1937.cpp ├── 1941.cpp ├── 19532.cpp ├── 19535.cpp ├── 19538.cpp ├── 19539.cpp ├── 1963.cpp ├── 1964.cpp ├── 1965.cpp ├── 19654.cpp ├── 1976.cpp ├── 1977.cpp ├── 1978.cpp ├── 1987.cpp ├── 1990.cpp ├── 1991.cpp ├── 1992.c ├── 2003.cpp ├── 2004.cpp ├── 2010.cpp ├── 2011.cpp ├── 2012.cpp ├── 20176.cpp ├── 2023.cpp ├── 2042.cpp ├── 2056.cpp ├── 2075.cpp ├── 2096.cpp ├── 21276.cpp ├── 2133.cpp ├── 2146.cpp ├── 2150.cpp ├── 2153.cpp ├── 2156.cpp ├── 2157.cpp ├── 2163.cpp ├── 2164.cpp ├── 2166.cpp ├── 2167.cpp ├── 2168.cpp ├── 21763.cpp ├── 21764.cpp ├── 21765.cpp ├── 2178.cpp ├── 2193.c ├── 2206.cpp ├── 2211.cpp ├── 2217.cpp ├── 2225.cpp ├── 2226.py ├── 2234.cpp ├── 2239.cpp ├── 2250.cpp ├── 2252.cpp ├── 2268.cpp ├── 2293.cpp ├── 2294.cpp ├── 2302.cpp ├── 2309.cpp ├── 2352.cpp ├── 2355.cpp ├── 2357.cpp ├── 2381.cpp ├── 2399.cpp ├── 2405.cpp ├── 2407.cpp ├── 2410.cpp ├── 2420.cpp ├── 2436.cpp ├── 2447.cpp ├── 2448.cpp ├── 2467.cpp ├── 2468.cpp ├── 2475.c ├── 2480.c ├── 2482.cpp ├── 2490.c ├── 2493.cpp ├── 2501.cpp ├── 2502.cpp ├── 2504.cpp ├── 2522.c ├── 2523.c ├── 2530.cpp ├── 2553.cpp ├── 2556.c ├── 2556.cpp ├── 2558.c ├── 2559.cpp ├── 2562.cpp ├── 2565.cpp ├── 2566.c ├── 2573.cpp ├── 2576.c ├── 2577.cpp ├── 2579.cpp ├── 2580.cpp ├── 2581.cpp ├── 2583.cpp ├── 2587.cpp ├── 2588.c ├── 2589.cpp ├── 2606.cpp ├── 2609.c ├── 2623.cpp ├── 2631.cpp ├── 2636.cpp ├── 2637.cpp ├── 2638.cpp ├── 2644.cpp ├── 2665.cpp ├── 2667.cpp ├── 2675.c ├── 2702.cpp ├── 2738.cpp ├── 2739.cpp ├── 2741.cpp ├── 2742.cpp ├── 2743.c ├── 2749.cpp ├── 2750.c ├── 2751.cpp ├── 2752.cpp ├── 2753.cpp ├── 2755.cpp ├── 2798.cpp ├── 2810.cpp ├── 2822.cpp ├── 2823.cpp ├── 2839.cpp ├── 2841.cpp ├── 2846.cpp ├── 2851.cpp ├── 2858.cpp ├── 2869.cpp ├── 2877.cpp ├── 2884.cpp ├── 2902.c ├── 2903.cpp ├── 2908.cpp ├── 2910.cpp ├── 2920.c ├── 2942.cpp ├── 2986.cpp ├── 2997.cpp ├── 2998.cpp ├── 3003.cpp ├── 3009.cpp ├── 3035.cpp ├── 3036.cpp ├── 3046.cpp ├── 3047.cpp ├── 3049.cpp ├── 3052.cpp ├── 3053.cpp ├── 3055.cpp ├── 3062.cpp ├── 3067.cpp ├── 3117.cpp ├── 3190.cpp ├── 3197.cpp ├── 3273.cpp ├── 3474.cpp ├── 3673.cpp ├── 3752.cpp ├── 3986.cpp ├── 4101.cpp ├── 4134.cpp ├── 4149.cpp ├── 4153.c ├── 4233.cpp ├── 4344.cpp ├── 4355.cpp ├── 4357.cpp ├── 4386.cpp ├── 4485.cpp ├── 4504.c ├── 4592.cpp ├── 4673.cpp ├── 4677.cpp ├── 4690.cpp ├── 4766.cpp ├── 4889.cpp ├── 4948.cpp ├── 4949.cpp ├── 4963.cpp ├── 4999.cpp ├── 5014.cpp ├── 5026.c ├── 5063.cpp ├── 5086.cpp ├── 5101.cpp ├── 5214.cpp ├── 5217.cpp ├── 5337.c ├── 5347.cpp ├── 5373.cpp ├── 5397.cpp ├── 5427.cpp ├── 5430.c ├── 5543.cpp ├── 5554.cpp ├── 5557.cpp ├── 5565.cpp ├── 5567.cpp ├── 5585.cpp ├── 5597.cpp ├── 5598.c ├── 5615.cpp ├── 5639.cpp ├── 5648.cpp ├── 5719.cpp ├── 5904.cpp ├── 5988.cpp ├── 6064.cpp ├── 6118.cpp ├── 6198.cpp ├── 6321.cpp ├── 6359.cpp ├── 6497.cpp ├── 6549.cpp ├── 6588.cpp ├── 6591.cpp ├── 6593.cpp ├── 6601.cpp ├── 6603.cpp ├── 6616.cpp ├── 6975.cpp ├── 7453.cpp ├── 7489.cpp ├── 7562.cpp ├── 7567.cpp ├── 7569.cpp ├── 7576.cpp ├── 7581.cpp ├── 7677.cpp ├── 7682.cpp ├── 7737.cpp ├── 7785.cpp ├── 7795.cpp ├── 8061.cpp ├── 8393.cpp ├── 8741.cpp ├── 8958.c ├── 8972.cpp ├── 9012.cpp ├── 9020.cpp ├── 9046.cpp ├── 9084.cpp ├── 9085.cpp ├── 9086.cpp ├── 9093.cpp ├── 9095.cpp ├── 9205.cpp ├── 9251.cpp ├── 9252.cpp ├── 9258.cpp ├── 9311.cpp ├── 9316.cpp ├── 9325.cpp ├── 9370.cpp ├── 9372.cpp ├── 9461.cpp ├── 9465.cpp ├── 9466.cpp ├── 9470.cpp ├── 9498.c ├── 9506.cpp ├── 9507.cpp ├── 9575.cpp ├── 9610.cpp ├── 9613.cpp ├── 9663.cpp ├── 9711.cpp ├── 9933.cpp ├── cpptest.cpp ├── playground.c └── playground.cpp ├── CodeJam ├── 2021 │ ├── 1A │ │ └── Append_Sort.py │ └── 1C │ │ ├── Closest_Pick.py │ │ ├── Double_or_NOTing.cpp │ │ └── Roaring_Years.cpp └── .gitkeep ├── LeetCode ├── .gitkeep ├── 01-matrix.cpp ├── 132-pattern.cpp ├── 2-keys-keyboard.cpp ├── 3sum-closest.cpp ├── 3sum-with-multiplicity.cpp ├── 3sum.cpp ├── 4sum-ii.cpp ├── accounts-merge.cpp ├── actors-and-directors-who-cooperated-at-least-three-times.mysql ├── add-binary.cpp ├── add-digits.cpp ├── add-minimum-number-of-rungs.cpp ├── add-one-row-to-tree.cpp ├── add-strings.cpp ├── add-to-array-form-of-integer.cpp ├── add-two-numbers-ii.cpp ├── add-two-numbers.cpp ├── adding-spaces-to-a-string.cpp ├── advantage-shuffle.cpp ├── all-elements-in-two-binary-search-trees.cpp ├── all-paths-from-source-to-target.cpp ├── all-possible-full-binary-trees.cpp ├── ambiguous-coordinates.cpp ├── arithmetic-slices-ii-subsequence.cpp ├── arithmetic-slices.cpp ├── arranging-coins.cpp ├── array-nesting.cpp ├── array-of-doubled-pairs.cpp ├── array-partition-i.cpp ├── article-views-i.mysql ├── asteroid-collision.cpp ├── average-of-levels-in-binary-tree.cpp ├── backspace-string-compare.cpp ├── balanced-binary-tree.cpp ├── bank-account-summary-ii.mysql ├── base-7.cpp ├── baseball-game.cpp ├── basic-calculator-ii.cpp ├── basic-calculator.py ├── beautiful-arrangement-ii.cpp ├── beautiful-arrangement.cpp ├── beautiful-array.cpp ├── best-time-to-buy-and-sell-stock-ii.cpp ├── best-time-to-buy-and-sell-stock-iii.cpp ├── best-time-to-buy-and-sell-stock-with-cooldown.cpp ├── best-time-to-buy-and-sell-stock-with-transaction-fee.cpp ├── best-time-to-buy-and-sell-stock.cpp ├── big-countries.mysql ├── binary-number-with-alternating-bits.cpp ├── binary-search-tree-iterator.cpp ├── binary-search-tree-to-greater-sum-tree.cpp ├── binary-subarrays-with-sum.cpp ├── binary-tree-cameras.cpp ├── binary-tree-inorder-traversal.cpp ├── binary-tree-level-order-traversal-ii.cpp ├── binary-tree-level-order-traversal.cpp ├── binary-tree-paths.cpp ├── binary-tree-postorder-traversal.cpp ├── binary-tree-preorder-traversal.cpp ├── binary-tree-pruning.cpp ├── binary-tree-right-side-view.cpp ├── binary-tree-tilt.cpp ├── binary-tree-zigzag-level-order-traversal.cpp ├── binary-trees-with-factors.cpp ├── bitwise-and-of-numbers-range.cpp ├── bitwise-ors-of-subarrays.cpp ├── boats-to-save-people.cpp ├── break-a-palindrome.cpp ├── brick-wall.cpp ├── broken-calculator.cpp ├── buddy-strings.cpp ├── build-an-array-with-stack-operations.cpp ├── bulls-and-cows.cpp ├── burst-balloons.cpp ├── calculate-money-in-leetcode-bank.cpp ├── calculate-special-bonus.mysql ├── can-place-flowers.cpp ├── candy.cpp ├── capital-gainloss.mysql ├── car-pooling.cpp ├── champagne-tower.cpp ├── check-array-formation-through-concatenation.cpp ├── check-if-a-string-contains-all-binary-codes-of-size-k.cpp ├── check-if-all-1s-are-at-least-length-k-places-away.cpp ├── check-if-every-row-and-column-contains-all-numbers.cpp ├── check-if-number-is-a-sum-of-powers-of-three.cpp ├── check-if-one-string-swap-can-make-strings-equal.cpp ├── check-if-there-is-a-valid-path-in-a-grid.cpp ├── cherry-pickup-ii.cpp ├── cinema-seat-allocation.cpp ├── circular-array-loop.cpp ├── climbing-stairs.cpp ├── clone-graph.cpp ├── coin-change-2.cpp ├── coin-change.cpp ├── coloring-a-border.cpp ├── combination-sum-ii.cpp ├── combination-sum-iii.cpp ├── combination-sum-iv.cpp ├── combination-sum.cpp ├── combinations.cpp ├── combine-two-tables.mysql ├── compare-strings-by-frequency-of-the-smallest-character.cpp ├── compare-version-numbers.py ├── complement-of-base-10-integer.cpp ├── complete-binary-tree-inserter.cpp ├── complex-number-multiplication.cpp ├── concatenation-of-consecutive-binary-numbers.cpp ├── consecutive-characters.cpp ├── consecutive-numbers-sum.cpp ├── construct-binary-search-tree-from-preorder-traversal.cpp ├── construct-binary-tree-from-inorder-and-postorder-traversal.cpp ├── construct-binary-tree-from-preorder-and-inorder-traversal.cpp ├── construct-quad-tree.cpp ├── construct-string-from-binary-tree.cpp ├── construct-target-array-with-multiple-sums.cpp ├── container-with-most-water.cpp ├── contains-duplicate.cpp ├── contiguous-array.cpp ├── continuous-subarray-sum.cpp ├── convert-1d-array-into-2d-array.cpp ├── convert-a-number-to-hexadecimal.cpp ├── convert-binary-number-in-a-linked-list-to-integer.cpp ├── convert-bst-to-greater-tree.cpp ├── convert-sorted-array-to-binary-search-tree.cpp ├── convert-sorted-list-to-binary-search-tree.cpp ├── convert-to-base-2.cpp ├── copy-list-with-random-pointer.cpp ├── count-all-valid-pickup-and-delivery-options.cpp ├── count-and-say.cpp ├── count-binary-substrings.cpp ├── count-complete-tree-nodes.cpp ├── count-good-nodes-in-binary-tree.cpp ├── count-good-numbers.cpp ├── count-nice-pairs-in-an-array.cpp ├── count-of-smaller-numbers-after-self.cpp ├── count-prefixes-of-a-given-string.cpp ├── count-primes.cpp ├── count-servers-that-communicate.cpp ├── count-sorted-vowel-strings.cpp ├── count-sub-islands.cpp ├── count-unguarded-cells-in-the-grid.cpp ├── count-vowels-permutation.cpp ├── counting-bits.cpp ├── course-schedule-ii.cpp ├── course-schedule-iii.cpp ├── course-schedule.cpp ├── crawler-log-folder.cpp ├── create-sorted-array-through-instructions.cpp ├── create-target-array-in-the-given-order.cpp ├── custom-sort-string.cpp ├── customer-placing-the-largest-number-of-orders.mysql ├── customer-who-visited-but-did-not-make-any-transactions.mysql ├── customers-who-never-order.mysql ├── daily-leads-and-partners.mysql ├── daily-temperatures.cpp ├── decode-string.py ├── decode-ways-ii.cpp ├── decode-ways.cpp ├── deepest-leaves-sum.cpp ├── degree-of-an-array.cpp ├── delete-and-earn.cpp ├── delete-columns-to-make-sorted.cpp ├── delete-duplicate-emails.mysql ├── delete-node-in-a-bst.cpp ├── delete-node-in-a-linked-list.cpp ├── delete-nodes-and-return-forest.cpp ├── delete-operation-for-two-strings.cpp ├── design-add-and-search-words-data-structure.cpp ├── design-bitset.cpp ├── design-circular-queue.cpp ├── design-hashmap.cpp ├── design-hashset.cpp ├── design-underground-system.cpp ├── detect-capital.cpp ├── determine-color-of-a-chessboard-square.cpp ├── determine-if-string-halves-are-alike.cpp ├── determine-if-two-strings-are-close.cpp ├── diagonal-traverse.cpp ├── diameter-of-binary-tree.cpp ├── different-ways-to-add-parentheses.cpp ├── distance-between-bus-stops.cpp ├── distant-barcodes.cpp ├── distinct-subsequences.cpp ├── distribute-candies.cpp ├── divide-array-in-sets-of-k-consecutive-numbers.cpp ├── domino-and-tromino-tiling.cpp ├── dungeon-game.cpp ├── duplicate-emails.mysql ├── edit-distance.cpp ├── element-appearing-more-than-25-in-sorted-array.cpp ├── eliminate-maximum-number-of-monsters.cpp ├── employee-importance.cpp ├── employees-with-missing-information.mysql ├── encode-and-decode-tinyurl.cpp ├── encrypt-and-decrypt-strings.cpp ├── erect-the-fence.cpp ├── escape-the-ghosts.cpp ├── escape-the-spreading-fire.cpp ├── evaluate-division.cpp ├── evaluate-reverse-polish-notation.cpp ├── excel-sheet-column-number.cpp ├── expression-add-operators.cpp ├── expressive-words.cpp ├── factorial-trailing-zeroes.cpp ├── fibonacci-number.cpp ├── find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree.cpp ├── find-all-anagrams-in-a-string.cpp ├── find-all-duplicates-in-an-array.cpp ├── find-all-groups-of-farmland.cpp ├── find-all-numbers-disappeared-in-an-array.cpp ├── find-and-replace-pattern.cpp ├── find-bottom-left-tree-value.cpp ├── find-closest-number-to-zero.cpp ├── find-customer-referee.mysql ├── find-duplicate-file-in-system.py ├── find-first-and-last-position-of-element-in-sorted-array.cpp ├── find-followers-count.mysql ├── find-k-closest-elements.cpp ├── find-k-pairs-with-smallest-sums.cpp ├── find-k-th-smallest-pair-distance.cpp ├── find-largest-value-in-each-tree-row.cpp ├── find-median-from-data-stream.cpp ├── find-minimum-in-rotated-sorted-array-ii.cpp ├── find-minimum-in-rotated-sorted-array.cpp ├── find-missing-observations.cpp ├── find-mode-in-binary-search-tree.cpp ├── find-n-unique-integers-sum-up-to-zero.cpp ├── find-nearest-point-that-has-the-same-x-or-y-coordinate.cpp ├── find-original-array-from-doubled-array.cpp ├── find-palindrome-with-fixed-length.cpp ├── find-peak-element.cpp ├── find-players-with-zero-or-one-losses.cpp ├── find-right-interval.cpp ├── find-smallest-letter-greater-than-target.cpp ├── find-target-indices-after-sorting-array.cpp ├── find-the-difference.cpp ├── find-the-duplicate-number.cpp ├── find-the-middle-index-in-array.cpp ├── find-the-most-competitive-subsequence.cpp ├── find-the-shortest-superstring.cpp ├── find-the-town-judge.cpp ├── find-the-winner-of-an-array-game.cpp ├── find-total-time-spent-by-each-employee.mysql ├── find-triangular-sum-of-an-array.cpp ├── find-winner-on-a-tic-tac-toe-game.cpp ├── finding-the-users-active-minutes.cpp ├── first-bad-version.cpp ├── first-missing-positive.cpp ├── first-unique-character-in-a-string.cpp ├── fix-names-in-a-table.mysql ├── fizz-buzz.cpp ├── flatten-a-multilevel-doubly-linked-list.cpp ├── flatten-binary-tree-to-linked-list.cpp ├── flatten-nested-list-iterator.cpp ├── flip-binary-tree-to-match-preorder-traversal.cpp ├── flip-string-to-monotone-increasing.cpp ├── flipping-an-image.cpp ├── flood-fill.cpp ├── frog-jump.cpp ├── fruit-into-baskets.cpp ├── furthest-building-you-can-reach.cpp ├── game-play-analysis-i.mysql ├── gas-station.cpp ├── generate-parentheses.cpp ├── generate-random-point-in-a-circle.cpp ├── get-biggest-three-rhombus-sums-in-a-grid.cpp ├── get-maximum-in-generated-array.cpp ├── get-watched-videos-by-your-friends.cpp ├── global-and-local-inversions.cpp ├── gray-code.cpp ├── greatest-sum-divisible-by-three.cpp ├── grid-illumination.cpp ├── group-anagrams.cpp ├── group-sold-products-by-the-date.mysql ├── group-the-people-given-the-group-size-they-belong-to.cpp ├── grumpy-bookstore-owner.cpp ├── guess-number-higher-or-lower.cpp ├── h-index-ii.cpp ├── h-index.cpp ├── hamming-distance.cpp ├── hand-of-straights.cpp ├── happy-number.cpp ├── house-robber-ii.cpp ├── house-robber-iii.cpp ├── house-robber.cpp ├── html-entity-parser.cpp ├── image-overlap.cpp ├── implement-magic-dictionary.cpp ├── implement-queue-using-stacks.cpp ├── implement-rand10-using-rand7.cpp ├── implement-stack-using-queues.cpp ├── implement-strstr.cpp ├── implement-trie-prefix-tree.cpp ├── increasing-decreasing-string.cpp ├── increasing-order-search-tree.cpp ├── increasing-subsequences.cpp ├── increasing-triplet-subsequence.cpp ├── insert-delete-getrandom-o1.cpp ├── insert-interval.cpp ├── insert-into-a-binary-search-tree.cpp ├── insertion-sort-list.cpp ├── integer-break.cpp ├── integer-replacement.cpp ├── integer-to-roman.cpp ├── interleaving-string.cpp ├── intersection-of-two-arrays-ii.cpp ├── intersection-of-two-arrays.cpp ├── intersection-of-two-linked-lists.cpp ├── interval-list-intersections.cpp ├── invert-binary-tree.cpp ├── is-graph-bipartite.cpp ├── is-subsequence.cpp ├── island-perimeter.cpp ├── isomorphic-strings.cpp ├── iterator-for-combination.cpp ├── jump-game-ii.cpp ├── jump-game-iii.cpp ├── jump-game-iv.cpp ├── jump-game-vi.cpp ├── jump-game.cpp ├── k-closest-points-to-origin.cpp ├── k-diff-pairs-in-an-array.cpp ├── k-inverse-pairs-array.cpp ├── keyboard-row.cpp ├── keys-and-rooms.cpp ├── knight-probability-in-chessboard.cpp ├── koko-eating-bananas.cpp ├── kth-ancestor-of-a-tree-node.cpp ├── kth-distinct-string-in-an-array.cpp ├── kth-largest-element-in-a-stream.cpp ├── kth-largest-element-in-an-array.cpp ├── kth-smallest-element-in-a-bst.cpp ├── kth-smallest-element-in-a-sorted-matrix.cpp ├── kth-smallest-number-in-multiplication-table.cpp ├── largest-1-bordered-square.cpp ├── largest-component-size-by-common-factor.cpp ├── largest-divisible-subset.cpp ├── largest-multiple-of-three.cpp ├── largest-number-after-digit-swaps-by-parity.cpp ├── largest-number-after-mutating-substring.cpp ├── largest-plus-sign.cpp ├── largest-rectangle-in-histogram.cpp ├── largest-submatrix-with-rearrangements.cpp ├── largest-triangle-area.cpp ├── largest-values-from-labels.cpp ├── last-moment-before-all-ants-fall-out-of-a-plank.cpp ├── last-stone-weight.cpp ├── lemonade-change.cpp ├── length-of-last-word.cpp ├── length-of-longest-fibonacci-subsequence.cpp ├── letter-case-permutation.cpp ├── letter-combinations-of-a-phone-number.cpp ├── lexicographical-numbers.cpp ├── lfu-cache.cpp ├── linked-list-cycle-ii.cpp ├── linked-list-cycle.cpp ├── linked-list-random-node.cpp ├── longest-common-prefix.cpp ├── longest-common-subsequence.cpp ├── longest-consecutive-sequence.cpp ├── longest-continuous-increasing-subsequence.cpp ├── longest-duplicate-substring.cpp ├── longest-happy-string.cpp ├── longest-harmonious-subsequence.cpp ├── longest-increasing-path-in-a-matrix.cpp ├── longest-increasing-subsequence.cpp ├── longest-mountain-in-array.cpp ├── longest-palindrome.cpp ├── longest-palindromic-subsequence.cpp ├── longest-palindromic-substring.cpp ├── longest-string-chain.cpp ├── longest-substring-without-repeating-characters.cpp ├── longest-turbulent-subarray.cpp ├── longest-uncommon-subsequence-i.cpp ├── longest-uncommon-subsequence-ii.cpp ├── longest-univalue-path.cpp ├── longest-valid-parentheses.cpp ├── longest-word-in-dictionary-through-deleting.cpp ├── longest-zigzag-path-in-a-binary-tree.cpp ├── lowest-common-ancestor-of-a-binary-search-tree.cpp ├── lowest-common-ancestor-of-a-binary-tree.cpp ├── lru-cache.cpp ├── lucky-numbers-in-a-matrix.cpp ├── majority-element-ii.cpp ├── majority-element.cpp ├── make-sum-divisible-by-p.cpp ├── making-a-large-island.cpp ├── map-of-highest-peak.cpp ├── map-sum-pairs.cpp ├── market-analysis-i.mysql ├── matchsticks-to-square.cpp ├── matrix-diagonal-sum.cpp ├── max-area-of-island.cpp ├── max-consecutive-ones-iii.cpp ├── max-consecutive-ones.cpp ├── max-number-of-k-sum-pairs.cpp ├── max-sum-of-rectangle-no-larger-than-k.cpp ├── maximal-rectangle.cpp ├── maximal-square.cpp ├── maximize-distance-to-closest-person.cpp ├── maximum-69-number.cpp ├── maximum-absolute-sum-of-any-subarray.cpp ├── maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.cpp ├── maximum-binary-tree.cpp ├── maximum-depth-of-n-ary-tree.cpp ├── maximum-difference-between-node-and-ancestor.cpp ├── maximum-element-after-decreasing-and-rearranging.cpp ├── maximum-erasure-value.cpp ├── maximum-frequency-stack.cpp ├── maximum-gap.cpp ├── maximum-length-of-a-concatenated-string-with-unique-characters.cpp ├── maximum-length-of-repeated-subarray.cpp ├── maximum-non-negative-product-in-a-matrix.cpp ├── maximum-number-of-balloons.cpp ├── maximum-number-of-coins-you-can-get.cpp ├── maximum-number-of-words-found-in-sentences.cpp ├── maximum-performance-of-a-team.cpp ├── maximum-points-you-can-obtain-from-cards.cpp ├── maximum-product-of-splitted-binary-tree.cpp ├── maximum-product-of-two-elements-in-an-array.cpp ├── maximum-product-of-word-lengths.cpp ├── maximum-product-subarray.cpp ├── maximum-score-from-performing-multiplication-operations.cpp ├── maximum-score-from-removing-stones.cpp ├── maximum-score-of-a-good-subarray.cpp ├── maximum-subarray.cpp ├── maximum-sum-obtained-of-any-permutation.cpp ├── maximum-sum-of-two-non-overlapping-subarrays.cpp ├── maximum-swap.cpp ├── maximum-units-on-a-truck.cpp ├── maximum-white-tiles-covered-by-a-carpet.cpp ├── maximum-width-of-binary-tree.cpp ├── maximum-width-ramp.cpp ├── maximum-xor-of-two-numbers-in-an-array.cpp ├── merge-in-between-linked-lists.cpp ├── merge-intervals.cpp ├── merge-k-sorted-lists.cpp ├── merge-sorted-array.cpp ├── merge-two-binary-trees.cpp ├── merge-two-sorted-lists.cpp ├── middle-of-the-linked-list.cpp ├── min-cost-climbing-stairs.cpp ├── min-cost-to-connect-all-points.cpp ├── min-stack.cpp ├── minesweeper.cpp ├── minimize-deviation-in-array.cpp ├── minimize-maximum-pair-sum-in-array.cpp ├── minimum-absolute-difference.cpp ├── minimum-add-to-make-parentheses-valid.cpp ├── minimum-average-difference.cpp ├── minimum-cost-for-tickets.cpp ├── minimum-cost-to-move-chips-to-the-same-position.cpp ├── minimum-deletions-to-make-character-frequencies-unique.cpp ├── minimum-depth-of-binary-tree.cpp ├── minimum-difference-between-highest-and-lowest-of-k-scores.cpp ├── minimum-domino-rotations-for-equal-row.cpp ├── minimum-falling-path-sum-ii.cpp ├── minimum-falling-path-sum.cpp ├── minimum-genetic-mutation.cpp ├── minimum-height-trees.cpp ├── minimum-increment-to-make-array-unique.cpp ├── minimum-index-sum-of-two-lists.cpp ├── minimum-insertions-to-balance-a-parentheses-string.cpp ├── minimum-interval-to-include-each-query.cpp ├── minimum-jumps-to-reach-home.cpp ├── minimum-length-of-string-after-deleting-similar-ends.cpp ├── minimum-moves-to-equal-array-elements-ii.cpp ├── minimum-moves-to-equal-array-elements.cpp ├── minimum-moves-to-reach-target-score.cpp ├── minimum-number-of-arrows-to-burst-balloons.cpp ├── minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix.cpp ├── minimum-number-of-refueling-stops.cpp ├── minimum-number-of-removals-to-make-mountain-array.cpp ├── minimum-number-of-steps-to-make-two-strings-anagram.cpp ├── minimum-operations-to-convert-number.cpp ├── minimum-operations-to-make-a-uni-value-grid.cpp ├── minimum-operations-to-make-array-equal.cpp ├── minimum-operations-to-reduce-x-to-zero.cpp ├── minimum-path-sum.cpp ├── minimum-remove-to-make-valid-parentheses.cpp ├── minimum-sideway-jumps.cpp ├── minimum-size-subarray-sum.cpp ├── minimum-swaps-to-make-strings-equal.cpp ├── minimum-time-difference.cpp ├── minimum-time-to-complete-trips.cpp ├── minimum-value-to-get-positive-step-by-step-sum.cpp ├── minimum-window-substring.cpp ├── mirror-reflection.cpp ├── missing-number.cpp ├── monotonic-array.cpp ├── move-zeroes.cpp ├── multiply-strings.cpp ├── my-calendar-i.cpp ├── my-calendar-ii.cpp ├── n-ary-tree-level-order-traversal.cpp ├── n-ary-tree-preorder-traversal.cpp ├── n-queens-ii.cpp ├── n-queens.cpp ├── n-repeated-element-in-size-2n-array.cpp ├── n-th-tribonacci-number.cpp ├── network-delay-time.cpp ├── next-greater-element-i.cpp ├── next-greater-element-ii.cpp ├── next-greater-node-in-linked-list.cpp ├── next-permutation.cpp ├── nim-game.cpp ├── non-decreasing-array.cpp ├── non-negative-integers-without-consecutive-ones.cpp ├── non-overlapping-intervals.cpp ├── nth-digit.cpp ├── nth-magical-number.cpp ├── number-complement.cpp ├── number-of-1-bits.cpp ├── number-of-boomerangs.cpp ├── number-of-closed-islands.cpp ├── number-of-dice-rolls-with-target-sum.cpp ├── number-of-different-integers-in-a-string.cpp ├── number-of-digit-one.cpp ├── number-of-islands.cpp ├── number-of-lines-to-write-string.cpp ├── number-of-longest-increasing-subsequence.cpp ├── number-of-matching-subsequences.cpp ├── number-of-pairs-of-strings-with-concatenation-equal-to-target.cpp ├── number-of-provinces.cpp ├── number-of-segments-in-a-string.cpp ├── number-of-steps-to-reduce-a-number-to-zero.cpp ├── number-of-subarrays-with-bounded-maximum.cpp ├── number-of-submatrices-that-sum-to-target.cpp ├── number-of-subsequences-that-satisfy-the-given-sum-condition.cpp ├── number-of-valid-words-for-each-puzzle.cpp ├── number-of-valid-words-in-a-sentence.py ├── number-of-ways-of-cutting-a-pizza.cpp ├── number-of-ways-to-paint-n-3-grid.cpp ├── number-of-ways-to-split-array.cpp ├── numbers-at-most-n-given-digit-set.cpp ├── numbers-with-same-consecutive-differences.cpp ├── odd-even-linked-list.cpp ├── ones-and-zeroes.cpp ├── open-the-lock.cpp ├── orderly-queue.cpp ├── out-of-boundary-paths.cpp ├── pacific-atlantic-water-flow.cpp ├── paint-house-iii.cpp ├── pairs-of-songs-with-total-durations-divisible-by-60.cpp ├── palindrome-linked-list.cpp ├── palindrome-number.cpp ├── palindrome-pairs.cpp ├── palindrome-partitioning-ii.cpp ├── palindrome-partitioning.cpp ├── palindromic-substrings.cpp ├── partition-array-into-disjoint-intervals.cpp ├── partition-array-into-three-parts-with-equal-sum.cpp ├── partition-equal-subset-sum.cpp ├── partition-labels.cpp ├── partition-list.cpp ├── partition-to-k-equal-sum-subsets.cpp ├── partitioning-into-minimum-number-of-deci-binary-numbers.cpp ├── pascals-triangle-ii.cpp ├── pascals-triangle.cpp ├── path-sum-ii.cpp ├── path-sum-iii.cpp ├── path-sum.cpp ├── path-with-maximum-gold.cpp ├── path-with-minimum-effort.cpp ├── patients-with-a-condition.mysql ├── peak-index-in-a-mountain-array.cpp ├── peeking-iterator.cpp ├── perfect-number.cpp ├── perfect-squares.cpp ├── permutation-in-string.cpp ├── permutations-ii.cpp ├── permutations.cpp ├── plates-between-candles.cpp ├── poor-pigs.cpp ├── populating-next-right-pointers-in-each-node-ii.cpp ├── populating-next-right-pointers-in-each-node.cpp ├── positions-of-large-groups.cpp ├── possible-bipartition.cpp ├── power-of-four.cpp ├── power-of-three.cpp ├── power-of-two.cpp ├── powerful-integers.cpp ├── powx-n.cpp ├── prefix-and-suffix-search.cpp ├── prison-cells-after-n-days.cpp ├── product-of-array-except-self.cpp ├── projection-area-of-3d-shapes.cpp ├── pseudo-palindromic-paths-in-a-binary-tree.cpp ├── push-dominoes.cpp ├── pyramid-transition-matrix.cpp ├── queue-reconstruction-by-height.cpp ├── rabbits-in-forest.cpp ├── random-flip-matrix.cpp ├── random-pick-index.cpp ├── range-addition-ii.cpp ├── range-sum-of-bst.cpp ├── range-sum-query-2d-immutable.cpp ├── range-sum-query-immutable.cpp ├── range-sum-query-mutable.cpp ├── ransom-note.cpp ├── reach-a-number.cpp ├── reachable-nodes-in-subdivided-graph.cpp ├── rearrange-products-table.mysql ├── rearrange-words-in-a-sentence.cpp ├── reconstruct-original-digits-from-english.cpp ├── recover-binary-search-tree.cpp ├── rectangle-area.cpp ├── recyclable-and-low-fat-products.mysql ├── reduce-array-size-to-the-half.cpp ├── reducing-dishes.cpp ├── redundant-connection-ii.cpp ├── redundant-connection.cpp ├── reformat-phone-number.cpp ├── reformat-the-string.cpp ├── regions-cut-by-slashes.cpp ├── regular-expression-matching.cpp ├── remove-all-adjacent-duplicates-in-string-ii.cpp ├── remove-all-adjacent-duplicates-in-string.cpp ├── remove-covered-intervals.cpp ├── remove-duplicate-letters.cpp ├── remove-duplicates-from-sorted-array-ii.cpp ├── remove-duplicates-from-sorted-array.cpp ├── remove-duplicates-from-sorted-list-ii.cpp ├── remove-duplicates-from-sorted-list.cpp ├── remove-element.cpp ├── remove-k-digits.cpp ├── remove-linked-list-elements.cpp ├── remove-nth-node-from-end-of-list.cpp ├── remove-palindromic-subsequences.cpp ├── removing-minimum-number-of-magic-beans.cpp ├── reorder-list.cpp ├── reorder-routes-to-make-all-paths-lead-to-the-city-zero.cpp ├── reordered-power-of-2.cpp ├── reorganize-string.cpp ├── replace-all-digits-with-characters.cpp ├── replace-elements-with-greatest-element-on-right-side.cpp ├── replace-words.cpp ├── reshape-the-matrix.cpp ├── restore-ip-addresses.cpp ├── reveal-cards-in-increasing-order.cpp ├── reverse-bits.cpp ├── reverse-integer.cpp ├── reverse-linked-list-ii.cpp ├── reverse-linked-list.cpp ├── reverse-nodes-in-k-group.cpp ├── reverse-only-letters.cpp ├── reverse-pairs.cpp ├── reverse-string-ii.cpp ├── reverse-string.cpp ├── reverse-vowels-of-a-string.cpp ├── reverse-words-in-a-string.py ├── richest-customer-wealth.cpp ├── rising-temperature.mysql ├── robot-bounded-in-circle.cpp ├── robot-return-to-origin.cpp ├── roman-to-integer.cpp ├── rotate-array.cpp ├── rotate-function.cpp ├── rotate-image.cpp ├── rotate-list.cpp ├── rotated-digits.cpp ├── rotting-oranges.cpp ├── running-sum-of-1d-array.cpp ├── russian-doll-envelopes.cpp ├── sales-analysis-iii.mysql ├── sales-person.mysql ├── same-tree.cpp ├── satisfiability-of-equality-equations.cpp ├── score-of-parentheses.cpp ├── scramble-string.cpp ├── search-a-2d-matrix-ii.cpp ├── search-a-2d-matrix.cpp ├── search-in-a-binary-search-tree.cpp ├── search-in-rotated-sorted-array.cpp ├── search-insert-position.cpp ├── search-suggestions-system.cpp ├── seat-reservation-manager.cpp ├── second-highest-salary.mysql ├── second-minimum-node-in-a-binary-tree.cpp ├── sentence-similarity-iii.cpp ├── sequential-digits.cpp ├── serialize-and-deserialize-binary-tree.py ├── set-matrix-zeroes.cpp ├── set-mismatch.cpp ├── shift-2d-grid.cpp ├── shifting-letters.cpp ├── short-encoding-of-words.cpp ├── shortest-bridge.cpp ├── shortest-distance-to-a-character.cpp ├── shortest-path-in-a-grid-with-obstacles-elimination.cpp ├── shortest-path-in-binary-matrix.cpp ├── shortest-path-with-alternating-colors.cpp ├── shortest-unsorted-continuous-subarray.cpp ├── shuffle-an-array.cpp ├── simplify-path.cpp ├── single-element-in-a-sorted-array.cpp ├── single-number-iii.cpp ├── single-number.cpp ├── single-threaded-cpu.cpp ├── sliding-window-maximum.cpp ├── sliding-window-median.cpp ├── slowest-key.cpp ├── smallest-index-with-equal-value.cpp ├── smallest-integer-divisible-by-k.cpp ├── smallest-string-with-a-given-numeric-value.cpp ├── smallest-string-with-swaps.cpp ├── snapshot-array.cpp ├── solve-the-equation.py ├── sort-an-array.cpp ├── sort-array-by-parity-ii.cpp ├── sort-array-by-parity.cpp ├── sort-characters-by-frequency.cpp ├── sort-colors.cpp ├── sort-even-and-odd-indices-independently.cpp ├── sort-list.cpp ├── sort-the-matrix-diagonally.cpp ├── spiral-matrix-ii.cpp ├── spiral-matrix.cpp ├── split-array-largest-sum.cpp ├── split-linked-list-in-parts.cpp ├── sqrtx.cpp ├── stamping-the-sequence.cpp ├── stone-game-iv.cpp ├── stone-game-vii.cpp ├── stone-game.cpp ├── stream-of-characters.cpp ├── string-compression.cpp ├── string-to-integer-atoi.cpp ├── student-attendance-record-ii.cpp ├── subarray-product-less-than-k.cpp ├── subarray-sum-equals-k.cpp ├── subarray-sums-divisible-by-k.cpp ├── subsets-ii.cpp ├── subsets.cpp ├── substring-with-concatenation-of-all-words.cpp ├── substrings-of-size-three-with-distinct-characters.cpp ├── sudoku-solver.cpp ├── sum-of-all-odd-length-subarrays.cpp ├── sum-of-beauty-of-all-substrings.cpp ├── sum-of-distances-in-tree.cpp ├── sum-of-left-leaves.cpp ├── sum-of-root-to-leaf-binary-numbers.cpp ├── sum-of-square-numbers.cpp ├── sum-of-unique-elements.cpp ├── sum-root-to-leaf-numbers.cpp ├── summary-ranges.cpp ├── super-palindromes.cpp ├── super-pow.cpp ├── surrounded-regions.cpp ├── swap-nodes-in-pairs.cpp ├── swap-salary.mysql ├── swapping-nodes-in-a-linked-list.cpp ├── swim-in-rising-water.cpp ├── symmetric-tree.cpp ├── target-sum.cpp ├── task-scheduler.cpp ├── the-k-weakest-rows-in-a-matrix.cpp ├── the-kth-factor-of-n.cpp ├── the-latest-login-in-2020.mysql ├── the-number-of-good-subsets.cpp ├── the-number-of-weak-characters-in-the-game.cpp ├── three-equal-parts.cpp ├── time-needed-to-inform-all-employees.cpp ├── to-lower-case.cpp ├── top-k-frequent-elements.cpp ├── top-k-frequent-words.cpp ├── top-travellers.mysql ├── total-hamming-distance.cpp ├── transform-to-chessboard.cpp ├── transpose-matrix.cpp ├── trapping-rain-water.cpp ├── tree-node.mysql ├── triangle.cpp ├── trim-a-binary-search-tree.cpp ├── truncate-sentence.cpp ├── two-city-scheduling.cpp ├── two-sum-ii-input-array-is-sorted.cpp ├── two-sum-iv-input-is-a-bst.cpp ├── two-sum.cpp ├── ugly-number-ii.cpp ├── ugly-number.cpp ├── unique-binary-search-trees.cpp ├── unique-email-addresses.py ├── unique-morse-code-words.cpp ├── unique-paths-ii.cpp ├── unique-paths-iii.cpp ├── unique-paths.cpp ├── user-activity-for-the-past-30-days-i.mysql ├── utf-8-validation.cpp ├── utils │ ├── .gitignore │ ├── api.py │ ├── cred.py │ ├── main.py │ ├── parse.py │ └── requirements.txt ├── valid-anagram.cpp ├── valid-mountain-array.cpp ├── valid-number.cpp ├── valid-palindrome-ii.cpp ├── valid-palindrome.cpp ├── valid-parentheses.cpp ├── valid-parenthesis-string.cpp ├── valid-perfect-square.cpp ├── valid-sudoku.cpp ├── valid-tic-tac-toe-state.cpp ├── valid-triangle-number.cpp ├── validate-binary-search-tree.cpp ├── validate-binary-tree-nodes.cpp ├── validate-stack-sequences.cpp ├── verify-preorder-serialization-of-a-binary-tree.py ├── verifying-an-alien-dictionary.cpp ├── vertical-order-traversal-of-a-binary-tree.cpp ├── vowel-spellchecker.cpp ├── vowels-of-all-substrings.cpp ├── walking-robot-simulation.cpp ├── water-and-jug-problem.cpp ├── water-bottles.cpp ├── wiggle-subsequence.cpp ├── word-break-ii.cpp ├── word-break.cpp ├── word-ladder-ii.cpp ├── word-ladder.cpp ├── word-pattern.py ├── word-search-ii.cpp ├── word-search.cpp ├── word-subsets.cpp ├── xor-operation-in-an-array.cpp ├── xor-queries-of-a-subarray.cpp └── zigzag-conversion.cpp ├── Misc ├── Complexity.md ├── KMP │ ├── README.md │ ├── kmp_dfa.cpp │ └── kmp_failurefunction.cpp └── SegmentTree │ ├── README.md │ ├── iterative.cpp │ ├── recursive.cpp │ └── recursive_lazy.cpp ├── Programmers ├── .gitkeep ├── 42576.cpp ├── 42577.cpp ├── 42578.cpp ├── 42584.cpp ├── 42626.cpp ├── 42748.cpp ├── 42839.cpp ├── 42862.cpp ├── 43162.cpp └── 43163.cpp ├── README.md ├── RUN ├── 2021 │ └── Spring_Contest │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── F.cpp │ │ └── README.md └── .gitkeep ├── SWExpertAcademy ├── .gitkeep ├── 10202.cpp ├── 10505.cpp ├── 8659.cpp └── 9940.cpp └── UCPC └── 2020 └── Qual ├── A.cpp ├── D.cpp ├── G.cpp └── H.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !/Baekjoon/ 3 | !/LeetCode/ 4 | !/Misc/ 5 | !/SWExpertAcademy/ 6 | !/Programmers/ 7 | !/RUN/ 8 | !/CodeJam/ 9 | !*.c 10 | !*.cpp 11 | !*.py 12 | !*.rb 13 | !.gitignore 14 | !*.md 15 | !.gitkeep 16 | tempCodeRunnerFile.* 17 | 18 | -------------------------------------------------------------------------------- /Baekjoon/1003.c: -------------------------------------------------------------------------------- 1 | #include 2 | int D[42]; 3 | 4 | int main(void) { 5 | D[0] = 1; 6 | for (int i = 2; i < 42; i++) { 7 | D[i] = D[i - 1] + D[i - 2]; 8 | } 9 | int T, a; scanf("%d", &T); 10 | for (int i = 0; i < T; i++) { 11 | scanf("%d", &a); printf("%d %d\n", D[a], D[a + 1]); 12 | } 13 | } -------------------------------------------------------------------------------- /Baekjoon/10039.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | int sum = 0, temp; 5 | for (int i = 0; i < 5; i++) { 6 | scanf("%d", &temp); if (temp < 40) { temp = 40; } 7 | sum += temp; 8 | } 9 | printf("%d", sum / 5); 10 | } -------------------------------------------------------------------------------- /Baekjoon/1008.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | double A, B; scanf("%lf %lf", &A, &B); 5 | double result = A / B; 6 | printf("%.17g", result); 7 | } -------------------------------------------------------------------------------- /Baekjoon/1009.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int T, a, b, m, n, x; cin >> T; 7 | for (int i = 0; i < T; i++) { 8 | cin >> a >> b; 9 | m = a % 2; // m = a ** b (mod 2) 10 | n = (a % 5 != 0); // n = a ** b (mod 5) 11 | for (int j = 0; j < b % 4; j++) { n *= a % 5; } 12 | x = (5 * m + 6 * n) % 10; // CRT 13 | cout << (x == 0 ? 10 : x) << '\n'; 14 | } 15 | } -------------------------------------------------------------------------------- /Baekjoon/10093.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(void) { 4 | ios::sync_with_stdio(0); cin.tie(0); 5 | unsigned long long a, b, temp; cin >> a >> b; 6 | if (a == b) { cout << 0; return 0; } 7 | if (a > b) { temp = a; a = b; b = temp; } 8 | cout << b - a - 1<< "\n"; 9 | for(unsigned long long i = a + 1; i < b; i++) { 10 | cout << i; 11 | if (i != b - 1) { cout << " "; } 12 | } 13 | } -------------------------------------------------------------------------------- /Baekjoon/1010.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int D[30][30]; 4 | 5 | int main(void) { 6 | ios::sync_with_stdio(0); cin.tie(0); 7 | int a, b, T; cin >> T; 8 | D[0][0] = 1; 9 | for (int i = 1; i < 30; i++) { 10 | D[i][0] = D[i][i] = 1; 11 | for (int j = 1; j <= i - 1; j++) { 12 | D[i][j] = D[i - 1][j - 1] + D[i - 1][j]; 13 | } 14 | } 15 | for (int i = 0; i < T; i++) { 16 | cin >> a >> b; cout << D[b][a] << '\n'; 17 | } 18 | } -------------------------------------------------------------------------------- /Baekjoon/10103.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int a, b, s1, s2, N; a = b = 100; 7 | cin >> N; 8 | while (N--) { 9 | cin >> s1 >> s2; 10 | if (s1 > s2) { b -= s1; } 11 | else if (s1 < s2) { a -= s2; } 12 | } 13 | cout << a << '\n' << b; 14 | } -------------------------------------------------------------------------------- /Baekjoon/10162.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; cin >> N; int A[3] = {300, 60, 10}, B[3] = {}; 7 | for (int i = 0; i < 3; i++) { 8 | B[i] = N / A[i]; N %= A[i]; 9 | } 10 | if (N == 0) { 11 | cout << B[0] << ' ' << B[1] << ' ' << B[2]; 12 | } else { 13 | cout << -1; 14 | } 15 | } -------------------------------------------------------------------------------- /Baekjoon/10171.c: -------------------------------------------------------------------------------- 1 | int main(){puts("\\ /\\\n ) ( ')\n( / )\n \\(__)|");} -------------------------------------------------------------------------------- /Baekjoon/10172.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | printf("|\\_/|\n|q p| /}\n( 0 )\"\"\"\\\n|\"^\"` |\n||_/=\\\\__|"); 4 | } -------------------------------------------------------------------------------- /Baekjoon/10178.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int T, a, b; cin >> T; 7 | for (int i = 0; i < T; i++) { 8 | cin >> a >> b; 9 | cout << "You get " << a / b<< " piece(s) and your dad gets " << a % b << " piece(s).\n"; 10 | } 11 | } -------------------------------------------------------------------------------- /Baekjoon/1026.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N, sum = 0; cin >> N; int A[N] = {}, B[N] = {}; 7 | for (int i = 0; i < N; i++) { cin >> A[i]; } 8 | for (int i = 0; i < N; i++) { cin >> B[i]; } 9 | sort(A, A + N); 10 | sort(B, B + N, greater()); 11 | for (int i = 0; i < N; i++) { sum += A[i] * B[i]; } 12 | cout << sum; 13 | } -------------------------------------------------------------------------------- /Baekjoon/10340.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | int A, B, C; scanf("%d %d %d", &A, &B, &C); 4 | int res1, res2, res3, res4; 5 | res1 = res2 = (A + B) % C; 6 | res3 = res4 = (A * B) % C; 7 | printf("%d\n%d\n%d\n%d", res1, res2, res3, res4); 8 | } -------------------------------------------------------------------------------- /Baekjoon/1037.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, result; cin >> N; int input[N] = {}; 7 | for (int i = 0; i < N; i++) { cin >> input[i]; } 8 | sort(input, input + N); 9 | cout << input[0] * input[N - 1]; 10 | } -------------------------------------------------------------------------------- /Baekjoon/10474.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int a, b; 7 | while (true) { 8 | cin >> a >> b; if (a == 0 && b == 0) { return 0; } 9 | cout << a / b << " " << (a % b) << " / " << b << '\n'; 10 | } 11 | } -------------------------------------------------------------------------------- /Baekjoon/10569.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int sum = 0, temp; 7 | for (int i = 0; i < 5; i++) { 8 | cin >> temp; sum += temp; 9 | } 10 | cout << sum; 11 | } -------------------------------------------------------------------------------- /Baekjoon/10718.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | printf("강한친구 대한육군\n강한친구 대한육군"); 3 | } -------------------------------------------------------------------------------- /Baekjoon/1074.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int rec(int n, int r, int c) { 5 | int half = 1 << (n - 1); 6 | int base = 0; 7 | if (c >= half) { base += half * half; c -= half; } 8 | if (r >= half) { base += half * half * 2; r -= half; } 9 | if (n == 1) { return base; } 10 | return base + rec(n - 1, r, c); 11 | } 12 | 13 | int main(void) { 14 | ios::sync_with_stdio(0); cin.tie(0); 15 | int N, r, c; cin >> N >> r >> c; 16 | cout << rec(N, r, c); 17 | } -------------------------------------------------------------------------------- /Baekjoon/1075.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int N, F; cin >> N >> F; 7 | N -= N % 100; 8 | int result = 0; 9 | for (int i = 0; i < 100; i++) { 10 | if (!((N + i) % F)) { result = i; break; } 11 | } 12 | if (result < 10) { cout << '0'; } 13 | cout << result; 14 | } -------------------------------------------------------------------------------- /Baekjoon/10768.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | int N, M; scanf("%d %d", &N, &M); 4 | if (N == 2 && M == 18) { printf("Special"); return 0; } 5 | if (N > 2) { printf("After"); return 0; } 6 | if (N == 2 && M > 18) { printf("After"); return 0; } 7 | printf("Before"); 8 | } -------------------------------------------------------------------------------- /Baekjoon/10773.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, temp; cin >> N; stack S; 7 | for (int i = 0; i < N; i++) { 8 | cin >> temp; 9 | if (temp != 0) { S.push(temp); } 10 | else { S.pop(); } 11 | } 12 | long long sum = 0; 13 | while (!S.empty()) { 14 | sum += S.top(); S.pop(); 15 | } 16 | cout << sum; 17 | } -------------------------------------------------------------------------------- /Baekjoon/10797.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int result = 0, T, temp; 7 | cin >> T; 8 | for (int i = 0; i < 5; i++) { 9 | cin >> temp; 10 | if (T == temp) 11 | result++; 12 | } 13 | cout << result; 14 | } -------------------------------------------------------------------------------- /Baekjoon/10804.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(void) { 4 | ios::sync_with_stdio(0); cin.tie(0); 5 | list L; for (int i = 1; i <= 20; i++) { L.push_back(i); } 6 | for (int t = 0; t < 10; t++) { 7 | int a, b; cin >> a >> b; 8 | auto it1 = L.begin(), it2 = L.begin(); advance(it1, a - 1); advance(it2, b); 9 | reverse(it1, it2); 10 | } 11 | for (auto it = L.begin(); it != L.end(); it++) { cout << *it << " "; } 12 | } -------------------------------------------------------------------------------- /Baekjoon/10807.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(void) { 4 | int N; cin >> N; short input[N] = {}; 5 | for (int i = 0; i < N; i++) { cin >> input[i]; } 6 | int m; cin >> m; int cnt = 0; 7 | for (int i = 0; i < N; i++) { cnt += (m == input[i]); } 8 | cout << cnt; 9 | } -------------------------------------------------------------------------------- /Baekjoon/10808.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) 5 | { 6 | ios::sync_with_stdio(0); 7 | cin.tie(0); 8 | string s; 9 | getline(cin, s); 10 | short array[26]; 11 | fill(array, array + 26, 0); 12 | for (int i = 0; i < s.size(); i++) { 13 | array[s[i] - 'a']++; 14 | } 15 | for (int i = 0; i < 26; i++) { 16 | cout << array[i]; 17 | if (i != 25) 18 | cout << " "; 19 | } 20 | } -------------------------------------------------------------------------------- /Baekjoon/10809.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | string s; int current; cin >> s; int D[26]; fill(D, D + 26, -1); 7 | for (int i = 0; i < s.length(); i++) { 8 | current = s[i] - 'a'; 9 | if (D[current] == -1) { D[current] = i; } 10 | } 11 | for (int i = 0; i < 26; i++) { 12 | cout << D[i] << " "; 13 | } 14 | } -------------------------------------------------------------------------------- /Baekjoon/10811.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int N, M, x, y; cin >> N >> M; int temp[N + 1] = {}; 7 | for (int i = 1; i <= N; i++) { temp[i] = i; } 8 | for (int i = 0; i < M; i++) { 9 | cin >> x >> y; 10 | reverse(temp + x, temp + y + 1); 11 | } 12 | for (int i = 1; i <= N; i++) { 13 | cout << temp[i] << ' '; 14 | } 15 | } -------------------------------------------------------------------------------- /Baekjoon/10817.c: -------------------------------------------------------------------------------- 1 | #include 2 | int max(int a, int b) { return a < b ? b : a; } 3 | int min(int a, int b) { return a < b ? a : b; } 4 | 5 | int main(void) { 6 | int a, b, c; scanf("%d %d %d", &a, &b, &c); 7 | printf("%d\n", a + b + c - min(min(a, b), c) - max(max(a, b), c)); 8 | } -------------------------------------------------------------------------------- /Baekjoon/10818.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | int min = 1000001, max = -min; 4 | int N, temp; scanf("%d", &N); 5 | for (int i = 0; i < N; i++) { 6 | scanf("%d", &temp); 7 | if (temp > max) { max = temp; } 8 | if (temp < min) { min = temp; } 9 | } 10 | printf("%d %d", min, max); 11 | } -------------------------------------------------------------------------------- /Baekjoon/10819.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; int input[N] = {}, idx[N] = {}; 7 | for (int i = 0; i < N; i++) { cin >> input[i]; idx[i] = i; } 8 | int cnt = 0, sum, max = -1; 9 | do { 10 | sum = 0; 11 | for (int i = 0; i < N - 1; i++) { 12 | sum += abs(input[idx[i]] - input[idx[i + 1]]); 13 | } 14 | if (max < sum) { max = sum; } 15 | } while (next_permutation(idx, idx + N)); 16 | cout << max; 17 | } -------------------------------------------------------------------------------- /Baekjoon/10820.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) { 5 | char input[101] = {}; 6 | while (scanf("%[^\n]%*c", input) != -1) { 7 | int lower = 0, upper = 0, num = 0, space = 0; 8 | for (int i = 0; i < strlen(input); i++) { 9 | if ('a' <= input[i] && 'z' >= input[i]) { lower++; } 10 | if ('A' <= input[i] && 'Z' >= input[i]) { upper++; } 11 | if (' ' == input[i]) { space++; } 12 | if ('0' <= input[i] && '9' >= input[i]) { num++; } 13 | } 14 | printf("%d %d %d %d\n", lower, upper, num, space); 15 | } 16 | } -------------------------------------------------------------------------------- /Baekjoon/10824.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | long long A, B, C, D; cin >> A >> B >> C >> D; 7 | long long result = B + D; 8 | while (B > 0) { A *= 10; B /= 10; } 9 | while (D > 0) { C *= 10; D /= 10; } 10 | cout << result + A + C; 11 | } -------------------------------------------------------------------------------- /Baekjoon/10844.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define NUM 1000000000 3 | int D[101][10]; 4 | 5 | int main(void) { 6 | int N; scanf("%d", &N); 7 | for (int i = 1; i < 10; i++) { D[1][i] = 1; } 8 | for (int i = 2; i <= N; i++) { 9 | for (int j = 0; j < 10; j++) { 10 | if (j - 1 >= 0) { D[i][j] = (D[i][j] + D[i - 1][j - 1]) % NUM; } 11 | if (j + 1 <= 9) { D[i][j] = (D[i][j] + D[i - 1][j + 1]) % NUM; } 12 | } 13 | } 14 | int result = 0; 15 | for (int i = 0; i < 10; i++) { result = (result + D[N][i]) % NUM; } 16 | printf("%d", result); 17 | } -------------------------------------------------------------------------------- /Baekjoon/1085.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int x, y, w, h; cin >> x >> y >> w >> h; 7 | int result = min(x, min(w - x, min(y, h - y))); 8 | cout << result; 9 | } -------------------------------------------------------------------------------- /Baekjoon/10867.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int cnt[2001]; 4 | 5 | int main(void) { 6 | ios::sync_with_stdio(0); cin.tie(0); 7 | int N, temp; cin >> N; 8 | for (int i = 0; i < N; i++) { 9 | cin >> temp; cnt[temp + 1000]++; 10 | } 11 | for (int i = 0; i <= 2000; i++) { 12 | if( cnt[i]) { cout << i - 1000 << ' '; } 13 | } 14 | } -------------------------------------------------------------------------------- /Baekjoon/10869.c: -------------------------------------------------------------------------------- 1 | int main(){int A,B;scanf("%d %d",&A,&B);printf("%d\n%d\n%d\n%d\n%d\n",A+B,A-B,A*B,A/B,A%B);} -------------------------------------------------------------------------------- /Baekjoon/10870.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fibo(int n) { 3 | if (n == 0) { return 0; } 4 | if (n == 1) { return 1; } 5 | return fibo(n - 1) + fibo(n - 2); 6 | } 7 | 8 | int main() { 9 | int N; scanf("%d", &N); 10 | printf("%d", fibo(N)); 11 | } -------------------------------------------------------------------------------- /Baekjoon/10871.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, X, temp; cin >> N >> X; 7 | for (int i = 0; i < N; i++) { 8 | cin >> temp; if (temp < X) { cout << temp << " "; } 9 | } 10 | } -------------------------------------------------------------------------------- /Baekjoon/10872.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int factorial(int n) { 3 | if (n <= 1) { return 1; } 4 | else { return n * factorial(n - 1); } 5 | } 6 | 7 | int main(void) { 8 | int N; scanf("%d", &N); 9 | printf("%d\n", factorial(N)); 10 | } -------------------------------------------------------------------------------- /Baekjoon/10886.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; int cnt = 0, temp; 7 | for (int i = 0; i < N; i++) { 8 | cin >> temp; if (temp) { cnt++; } 9 | } 10 | cout << "Junhee is "; 11 | if (cnt <= N / 2) { cout << "not "; } 12 | cout << "cute!"; 13 | } -------------------------------------------------------------------------------- /Baekjoon/10926.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | char input[51] = {}; scanf("%s", &input); 5 | printf("%s", input); printf("?"); printf("?"); printf("!"); 6 | } -------------------------------------------------------------------------------- /Baekjoon/10930.py: -------------------------------------------------------------------------------- 1 | import hashlib 2 | s = input() 3 | print(hashlib.sha256(s.encode()).hexdigest()) -------------------------------------------------------------------------------- /Baekjoon/10932.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | from hashlib import sha512 3 | s = input().encode() 4 | print(sha512(s).hexdigest()) -------------------------------------------------------------------------------- /Baekjoon/1094.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N, result = 0; 7 | cin >> N; 8 | while (N > 0) { 9 | if (N & 1) 10 | result++; 11 | N >>= 1; 12 | } 13 | cout << result; 14 | } -------------------------------------------------------------------------------- /Baekjoon/10950.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int N, a, b; scanf("%d\n", &N); 3 | for (int i = 0; i < N; i++) { 4 | scanf("%d %d", &a, &b); printf("%d\n", a + b); 5 | } 6 | } -------------------------------------------------------------------------------- /Baekjoon/10951.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a, b; 3 | while (scanf("%d %d", &a, &b) != -1) { 4 | printf("%d\n", a + b); 5 | } 6 | } -------------------------------------------------------------------------------- /Baekjoon/10952.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | int a, b; 4 | while (1) { 5 | scanf("%d %d", &a, &b); 6 | if (a == 0 && b == 0) { break; } 7 | printf("%d\n", a + b); 8 | } 9 | } -------------------------------------------------------------------------------- /Baekjoon/10953.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | int T; scanf("%d", &T); char input[4]; 4 | for (int i = 0; i < T; i++) { 5 | scanf("%s", &input); printf("%d\n", input[0] + input[2] - '0' * 2); 6 | } 7 | } -------------------------------------------------------------------------------- /Baekjoon/10987.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | string s; cin >> s; int cnt = 0; 7 | for (int i = 0; i < s.length(); i++) { 8 | if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || 9 | s[i] == 'o' || s[i] == 'u') { cnt++; } 10 | } 11 | cout << cnt; 12 | } -------------------------------------------------------------------------------- /Baekjoon/10988.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(void) { 4 | char input[101] = {}; scanf("%s", input); int l = strlen(input); 5 | for (int i = 0; i < l; i++) { 6 | if (input[i] != input[l - 1 - i]) { printf("0"); return 0; } 7 | } 8 | printf("1"); 9 | } -------------------------------------------------------------------------------- /Baekjoon/10989.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int cnt[10001]; 4 | 5 | int main(void) { 6 | ios::sync_with_stdio(0); cin.tie(0); 7 | int N, temp; cin >> N; 8 | for (int i = 0; i < N; i++) { 9 | cin >> temp; cnt[temp]++; 10 | } 11 | for (int i = 1; i <= 10000; i++) { 12 | for (int j = 0; j < cnt[i]; j++) { 13 | cout << i << '\n'; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Baekjoon/10990.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | int N; scanf("%d", &N); 5 | for (int i = 0; i < N; i++) { 6 | for (int j = 0; j < N + i; j++) { 7 | if (j == N + i - 1 || j == N - i - 1) { printf("*"); } else { printf(" "); } 8 | } 9 | printf("\n"); 10 | } 11 | 12 | } -------------------------------------------------------------------------------- /Baekjoon/10991.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | int N; scanf("%d", &N); 5 | for (int i = 0; i < N; i++) { 6 | for (int j = 0; j < N + i; j++) { 7 | if ((j - (N + i - 1)) % 2 == 0 && j >= N - 1 - i) { printf("*"); } else { printf(" "); } 8 | } 9 | printf("\n"); 10 | } 11 | } -------------------------------------------------------------------------------- /Baekjoon/10992.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | int N; scanf("%d", &N); 5 | for (int i = 0; i < N - 1; i++) { 6 | for (int j = 0; j < N + i; j++) { 7 | if (j == N + i - 1 || j == N - i - 1) { printf("*"); } else { printf(" "); } 8 | } 9 | printf("\n"); 10 | } 11 | for (int j = 0; j < 2 * N - 1; j++) { printf("*"); } 12 | } -------------------------------------------------------------------------------- /Baekjoon/10995.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int N; cin >> N; 7 | for (int i = 0; i < N; i++) { 8 | for (int j = 0; j < 2 * N - 1; j++) { 9 | if (!((i % 2 + j) % 2)) { cout << '*'; } 10 | else { cout << ' '; } 11 | } 12 | if (i % 2) { cout << '*'; } 13 | cout << '\n'; 14 | } 15 | } -------------------------------------------------------------------------------- /Baekjoon/10996.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; if (N == 1) { cout << '*'; return 0; } 7 | for (int i = 0; i < N; i++) { 8 | for (int j = N / 2; j < N; j++) { 9 | cout << '*'; if (j < N - 1) { cout << ' '; } 10 | } 11 | cout << '\n'; 12 | for (int j = 0; j < N / 2; j++) { 13 | cout << " *"; 14 | } 15 | cout << '\n'; 16 | } 17 | } -------------------------------------------------------------------------------- /Baekjoon/10998.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void){ 3 | int a, b; scanf("%d %d", &a, &b); 4 | printf("%d\n", a * b); 5 | } -------------------------------------------------------------------------------- /Baekjoon/1100.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | char temp; bool flip = true; int result = 0; 7 | for (int i = 0; i < 8; i++) { 8 | for (int j = 0; j < 8; j++) { 9 | cin >> temp; 10 | if (flip && temp == 'F') { result++; } 11 | flip = !flip; 12 | } 13 | flip = !flip; 14 | } 15 | cout << result; 16 | } -------------------------------------------------------------------------------- /Baekjoon/11004.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N, K; cin >> N >> K; int input[N] = {}; 7 | for (int i = 0; i < N; i++) { cin >> input[i]; } 8 | nth_element(input, input + K - 1, input + N); cout << input[K - 1]; 9 | } -------------------------------------------------------------------------------- /Baekjoon/11021.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | int a, b, T; scanf("%d", &T); char input[4] = {}; 4 | for (int i = 0; i < T; i++) { 5 | scanf("%d %d", &a, &b); 6 | printf("Case #%d: %d\n", i + 1, a + b); 7 | } 8 | } -------------------------------------------------------------------------------- /Baekjoon/11022.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int T, a, b; scanf("%d", &T); 3 | for (int i = 1; i <= T; i++) { 4 | scanf("%d %d", &a, &b); printf("Case #%d: %d + %d = %d\n", i, a, b, a + b); 5 | } 6 | } -------------------------------------------------------------------------------- /Baekjoon/11047.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N, K, result = 0, idx; cin >> N >> K; int A[N] = {}; 7 | for (int i = 0; i < N; i++) { 8 | cin >> A[i]; 9 | } 10 | idx = N - 1; 11 | while (K != 0) { 12 | if (K >= A[idx]) { 13 | result += K / A[idx]; 14 | K %= A[idx]; 15 | } 16 | idx--; 17 | } 18 | cout << result; 19 | } -------------------------------------------------------------------------------- /Baekjoon/11050.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int D[1001][1001]; 4 | 5 | int main(void) { 6 | ios::sync_with_stdio(0); cin.tie(0); 7 | int N, K; cin >> N >> K; 8 | D[1][0] = D[1][1] = 1; 9 | for (int n = 2; n <= N; n++) { 10 | D[n][0] = D[n][n] = 1; 11 | for (int k = 1; k <= n - 1; k++) { 12 | D[n][k] = (D[n - 1][k - 1] + D[n - 1][k]); 13 | } 14 | } 15 | cout << D[N][K]; 16 | } -------------------------------------------------------------------------------- /Baekjoon/11051.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int D[1001][1001]; 4 | 5 | int main(void) { 6 | ios::sync_with_stdio(0); cin.tie(0); 7 | int N, K; cin >> N >> K; 8 | D[1][0] = D[1][1] = 1; 9 | for (int n = 2; n <= N; n++) { 10 | D[n][0] = D[n][n] = 1; 11 | for (int k = 1; k <= n - 1; k++) { 12 | D[n][k] = (D[n - 1][k - 1] + D[n - 1][k]) % 10007; 13 | } 14 | } 15 | cout << D[N][K]; 16 | } -------------------------------------------------------------------------------- /Baekjoon/11057.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; int D[N][10] = {}; 7 | for (int i = 0; i < 10; i++) { D[0][i] = 1; } 8 | for (int i = 1; i < N; i++) { 9 | for (int j = 0; j < 10; j++) { 10 | for (int k = j; k < 10; k++) { 11 | D[i][j] = (D[i][j] + D[i - 1][k]) % 10007; 12 | } 13 | } 14 | } 15 | int result = 0; 16 | for (int i = 0; i < 10; i++) { result += D[N - 1][i]; } result %= 10007; 17 | cout << result; 18 | } -------------------------------------------------------------------------------- /Baekjoon/1110.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, start, trial = 0; bool less; cin >> N; start = N; 7 | do { 8 | less = false; 9 | if (N < 10) { N *= 10; less = true;} 10 | N = (less ? N / 10 : N % 10) * 10 + ((N / 10 + N % 10) % 10); 11 | trial++; 12 | } while (N != start); 13 | cout << trial; 14 | } -------------------------------------------------------------------------------- /Baekjoon/1120.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | string A, B; 7 | cin >> A >> B; 8 | int Min = 1 << 30; 9 | for (int i = 0; i < B.length() - A.length() + 1; i++) { 10 | int num_diff = 0; 11 | for (int j = 0; j < A.length(); j++) 12 | if (A[j] != B[i + j]) 13 | num_diff++; 14 | Min = min(Min, num_diff); 15 | } 16 | cout << Min; 17 | } -------------------------------------------------------------------------------- /Baekjoon/11279.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | priority_queue PQ; 7 | int N, temp; cin >> N; 8 | for (int i = 0; i < N; i++) { 9 | cin >> temp; 10 | if (temp == 0) { 11 | if (PQ.empty()) { cout << "0\n"; } 12 | else { cout << PQ.top() << '\n'; PQ.pop(); } 13 | } else { PQ.push(temp); } 14 | } 15 | } -------------------------------------------------------------------------------- /Baekjoon/11328.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(void) { 4 | ios::sync_with_stdio(0); cin.tie(0); 5 | string s; getline(cin, s); int N = stoi(s); 6 | for (int i = 0; i < N; i++) { 7 | string a, b; cin >> a >> b; if (a.size() != b.size()) { cout << "Impossible\n"; continue; } 8 | list a1 (a.begin(), a.end()); a1.sort(); 9 | list b1 (b.begin(), b.end()); b1.sort(); 10 | if (!equal(a1.begin(), a1.end(), b1.begin())) { cout << "Impossible\n"; continue; } 11 | cout << "Possible\n"; 12 | } 13 | } -------------------------------------------------------------------------------- /Baekjoon/11365.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | string s; 7 | while (true) { 8 | getline(cin, s); if (!s.compare("END")) { return 0; } 9 | reverse(s.begin(), s.end()); 10 | cout << s << '\n'; 11 | } 12 | } -------------------------------------------------------------------------------- /Baekjoon/11441.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N, M, start, end; int acc = 0, temp; cin >> N; 7 | int D[N + 1] = {}; // DP 8 | for (int i = 1; i <= N; i++) { 9 | cin >> temp; acc += temp; D[i] = acc; 10 | } 11 | cin >> M; 12 | for (int i = 0; i < M; i++) { 13 | cin >> start >> end; 14 | cout << D[end] - D[start - 1] << '\n'; 15 | } 16 | } -------------------------------------------------------------------------------- /Baekjoon/11478.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | string s; cin >> s; 7 | int N = s.size(); 8 | unordered_set S; 9 | for (int i = 1; i <= N; i++) { 10 | for (int j = 0; j <= N - i; j++) { 11 | auto k = s.substr(j, i); 12 | S.insert(k); 13 | } 14 | } 15 | cout << S.size(); 16 | } -------------------------------------------------------------------------------- /Baekjoon/1152.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(void) { 4 | ios::sync_with_stdio(0); cin.tie(0); string s; getline(cin, s); 5 | int result = 0; bool in = false; char *input = (char *)s.c_str(); 6 | for (int i = 0; i < s.length(); i++) { 7 | if (input[i] != ' ' && !in) { result++; in = true; } 8 | else if (input[i] == ' ') { in = false; } 9 | } 10 | cout << result; 11 | } -------------------------------------------------------------------------------- /Baekjoon/1157.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int alphabet[26] = {}; string s; 7 | getline(cin, s); int Max = -1; 8 | for (auto it = s.begin(); it != s.end(); it++) { 9 | Max = max(Max, ++alphabet[*it <= 'Z' ? *it - 'A' : *it - 'a']); 10 | } 11 | int cnt = 0, idx; 12 | for (int i = 0; i < 26; i++) { 13 | if (Max == alphabet[i]) { cnt++; idx = i; } 14 | } 15 | cout << (cnt == 1 ? (char)(idx + 'A') : '?'); 16 | } -------------------------------------------------------------------------------- /Baekjoon/11575.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | inline void task(void) { 5 | int a, b; string s; 6 | cin >> a >> b >> s; 7 | for (int i = 0; i < s.size(); i++) { 8 | s[i] = 'A' + ((s[i] - 'A') * a + b) % 26; 9 | } 10 | cout << s << '\n'; 11 | } 12 | 13 | int main(void) { 14 | ios::sync_with_stdio(false); cin.tie(nullptr); 15 | int T; 16 | cin >> T; 17 | while (T--) 18 | task(); 19 | } -------------------------------------------------------------------------------- /Baekjoon/1159.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | string s; int N; getline(cin, s); N = stoi(s); 7 | int charset[26] = {}; 8 | for (int i = 0; i < N; i++) { 9 | getline(cin, s); 10 | charset[s[0] - 'a']++; 11 | } 12 | bool found = false; 13 | for (int i = 0; i < 26; i++) { 14 | if (charset[i] >= 5) { found = true; cout << (char)(i + 'a'); } 15 | } 16 | if (!found) { cout << "PREDAJA"; } 17 | 18 | } -------------------------------------------------------------------------------- /Baekjoon/11650.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | int N, a, b; cin >> N; pair input[N]; 6 | for (int i = 0; i < N; i++) { 7 | cin >> a >> b; input[i] = {a, b}; 8 | } 9 | sort(input, input + N); 10 | for (int i = 0; i < N; i++) { 11 | cout << input[i].first << " " << input[i].second << "\n"; 12 | } 13 | } -------------------------------------------------------------------------------- /Baekjoon/11651.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | int N, a, b; cin >> N; pair input[N]; 6 | for (int i = 0; i < N; i++) { 7 | cin >> a >> b; input[i] = {b, a}; 8 | } 9 | sort(input, input + N); 10 | for (int i = 0; i < N; i++) { 11 | cout << input[i].second << " " << input[i].first << "\n"; 12 | } 13 | } -------------------------------------------------------------------------------- /Baekjoon/11652.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | // O(N * log(N)) 7 | int N; long long temp; cin >> N; 8 | unordered_map M; 9 | for (int i = 0; i < N; i++) { 10 | cin >> temp; 11 | M[temp]++; 12 | } 13 | vector > data; 14 | for (auto it : M) 15 | data.push_back({it.second, -it.first}); 16 | sort(data.begin(), data.end()); 17 | cout << -(*data.rbegin()).second; 18 | } -------------------------------------------------------------------------------- /Baekjoon/11653.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; 7 | for (int i = 2; i * i <= N; i++) { 8 | while (N % i == 0) { 9 | cout << i << '\n'; 10 | N /= i; 11 | } 12 | } 13 | if (N != 1) cout << N; 14 | } -------------------------------------------------------------------------------- /Baekjoon/11654.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(void) { 4 | ios::sync_with_stdio(0); cin.tie(0); 5 | char N; cin >> N; cout << (int)N; 6 | } -------------------------------------------------------------------------------- /Baekjoon/11655.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | char *input; string s; getline(cin, s); input = (char *)s.c_str(); 7 | int len = strlen(input); 8 | for (int i = 0; i < len; i++) { 9 | if (input[i] == ' ' || (input[i] >= '0' && input[i] <= '9')) { continue; } 10 | if (input[i] >= 'a' && input[i] <= 'z') { input[i] = 'a' + (input[i] - 'a' + 13) % 26; } 11 | if (input[i] >= 'A' && input[i] <= 'Z') { input[i] = 'A' + (input[i] - 'A' + 13) % 26; } 12 | } 13 | printf("%s", input); 14 | } -------------------------------------------------------------------------------- /Baekjoon/11656.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | // O(N * log(N)) 7 | string temp; cin >> temp; 8 | vector input; 9 | for (int i = 0; i < temp.size(); i++) 10 | input.push_back(temp.substr(i, temp.size())); 11 | sort(input.begin(), input.end()); 12 | for (auto it : input) 13 | cout << it << '\n'; 14 | } -------------------------------------------------------------------------------- /Baekjoon/11659.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N, M; cin >> N >> M; int D[N + 1] = {}; 7 | int start, end; 8 | for (int i = 1; i <= N; i++) { 9 | cin >> D[i]; D[i] += D[i - 1]; 10 | } 11 | for (int i = 0; i < M; i++) { 12 | cin >> start >> end; 13 | cout << D[end] - D[start - 1] << '\n'; 14 | } 15 | } -------------------------------------------------------------------------------- /Baekjoon/11660.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N, M, x1, y1, x2, y2, temp; cin >> N >> M; int D[N + 1][N + 1] = {}; 7 | for (int i = 0; i < N; i++) { 8 | for (int j = 0; j < N; j++) { 9 | cin >> temp; 10 | D[i + 1][j + 1] = D[i][j + 1] + D[i + 1][j] - D[i][j] + temp; 11 | } 12 | } 13 | for (int t = 0; t < M; t++) { 14 | cin >> x1 >> y1 >> x2 >> y2; 15 | cout << D[x2][y2] - D[x1 - 1][y2] - D[x2][y1 - 1] + D[x1 - 1][y1 - 1] << '\n'; 16 | } 17 | } -------------------------------------------------------------------------------- /Baekjoon/11718.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(void) { 4 | string s; 5 | while(getline(cin, s)) { cout << s << '\n'; } 6 | } -------------------------------------------------------------------------------- /Baekjoon/11719.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | string s; 7 | while (!cin.eof()) { 8 | getline(cin, s); cout << s << '\n'; 9 | } 10 | } -------------------------------------------------------------------------------- /Baekjoon/11720.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | int len; scanf("%d", &len); 4 | char input[len + 1]; scanf("%s", &input); 5 | int sum = 0; 6 | for (int i = 0; i < len; i++) { 7 | sum += (input[i] - '0'); 8 | } 9 | printf("%d", sum); 10 | } -------------------------------------------------------------------------------- /Baekjoon/11721.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) { 5 | char input[101] = {}; scanf("%s", input); 6 | for (int i = 1; i <= strlen(input); i++) { 7 | printf("%c", input[i - 1]); 8 | if (i % 10 == 0) { printf("\n"); } 9 | } 10 | } -------------------------------------------------------------------------------- /Baekjoon/11722.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, result = 0; cin >> N; int input[N] = {}; 7 | for (int i = 0; i < N; i++) { cin >> input[i]; } 8 | int D[N] = {}; 9 | for (int i = 0; i < N; i++) { 10 | for (int j = i - 1; j >= 0; j--) { 11 | if (input[i] < input[j]) { 12 | D[i] = max(D[j], D[i]); 13 | } 14 | } 15 | D[i]++; 16 | if (D[i] > result) { result = D[i]; } 17 | } 18 | cout << result; 19 | } -------------------------------------------------------------------------------- /Baekjoon/11726.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int D[1001]; 4 | 5 | int main(void) { 6 | ios::sync_with_stdio(0); cin.tie(0); 7 | int N; cin >> N; 8 | D[1] = 1; D[2] = 2; 9 | for (int k = 3; k <= N; k++) { 10 | D[k] = (D[k - 1] + D[k - 2]) % 10007; 11 | } 12 | cout << D[N]; 13 | } -------------------------------------------------------------------------------- /Baekjoon/11727.c: -------------------------------------------------------------------------------- 1 | #include 2 | int D[1001][2]; 3 | 4 | int main(void) { 5 | int N; scanf("%d", &N); 6 | D[1][0] = 0; D[1][1] = 1; D[2][0] = 2; D[2][1] = 1; 7 | for (int i = 3; i <= N; i++) { 8 | D[i][0] = (2 * (D[i - 2][0] + D[i - 2][1])) % 10007; 9 | D[i][1] = (D[i - 1][0] + D[i - 1][1]) % 10007; 10 | } 11 | printf("%d", (D[N][0] + D[N][1]) % 10007); 12 | } -------------------------------------------------------------------------------- /Baekjoon/11729.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void hanoi(int height, int src, int dest) { 4 | if (height == 1) { 5 | cout << src << " " << dest << "\n"; 6 | } else { 7 | hanoi(height - 1, src, 6 - src - dest); 8 | hanoi(1, src, dest); 9 | hanoi(height - 1, 6 - src - dest, dest); 10 | } 11 | } 12 | 13 | int main(void) { 14 | ios::sync_with_stdio(0); cin.tie(0); 15 | int N; cin >> N; 16 | cout << (int)(pow(2, N) - 1) << '\n'; 17 | hanoi(N, 1, 3); 18 | } -------------------------------------------------------------------------------- /Baekjoon/11758.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int x[3] = {}, y[3] = {}; 7 | for (int i = 0; i < 3; i++) { cin >> x[i] >> y[i]; } 8 | int x1 = x[1] - x[0], y1 = y[1] - y[0]; 9 | int x2 = x[2] - x[1], y2 = y[2] - y[1]; 10 | int result = x1 * y2 - x2 * y1; // Cross product 11 | if (result == 0) { cout << 0; return 0; } 12 | cout << (result > 0 ? 1 : -1); 13 | } -------------------------------------------------------------------------------- /Baekjoon/11819.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | __int128_t power(__int128_t a, __int128_t b, __int128_t c) { 5 | if (c == 1) { return 0; } 6 | if (b == 0) { return 1; } 7 | __int128_t temp = power(a, b / 2, c); 8 | __int128_t k = temp * temp % c; 9 | if (b % 2 == 0) { 10 | return k; 11 | } else { 12 | return k * a % c; 13 | } 14 | } 15 | 16 | int main(void) { 17 | ios::sync_with_stdio(false); cin.tie(nullptr); 18 | long long A, B, C; cin >> A >> B >> C; 19 | cout << static_cast(power(A, B, C) % C); 20 | } -------------------------------------------------------------------------------- /Baekjoon/1182.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int input[20]; int N, S, temp; cin >> N >> S; 7 | for (int i = 0; i < N; i++) { cin >> temp; input[i] = temp; } 8 | int result = 0; int sum = 0; 9 | for (int i = 1; i < (1 << N); i++) { 10 | temp = i; 11 | for (int j = 0; j < N; j++) { 12 | if (temp & 1) { sum += input[j]; } temp >>= 1; 13 | } 14 | if (sum == S) { result++; } 15 | sum = 0; 16 | } 17 | cout << result; 18 | } -------------------------------------------------------------------------------- /Baekjoon/1193.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int X; cin >> X; int N; 7 | int i = (int)sqrt(X) - 1; 8 | while (true) { 9 | if (i * (i + 1) / 2 < X) { i++; } 10 | else { 11 | int temp = X - (i - 1) * i / 2; 12 | if (i % 2) { cout << i - temp + 1 << '/' << temp; } 13 | else { cout << temp << '/' << i - temp + 1; } 14 | return 0; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Baekjoon/11945.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N, M; cin >> N >> M; char s[M + 1] = {}; 7 | while (N--) { 8 | cin >> s; 9 | for (int i = M - 1; i >= 0; i--) { 10 | cout << s[i]; 11 | } 12 | cout << '\n'; 13 | } 14 | } -------------------------------------------------------------------------------- /Baekjoon/11966.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; 7 | while (N > 1) { 8 | if (N & 1) { cout << 0; return 0; } 9 | N >>= 1; 10 | } 11 | cout << 1; 12 | } -------------------------------------------------------------------------------- /Baekjoon/12015.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; cin >> N; vector D; 7 | for (int i = 0; i < N; i++) { // LIS 8 | int temp; cin >> temp; // O(N * log(N)) 9 | auto it = lower_bound(D.begin(), D.end(), temp); 10 | if (it == D.end()) { 11 | D.push_back(temp); 12 | } else { 13 | *it = temp; 14 | } 15 | } 16 | cout << D.size(); 17 | } -------------------------------------------------------------------------------- /Baekjoon/1225.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) { 5 | char a[10001] = {}, b[10001] = {}; scanf("%s %s", a, b); 6 | int al = strlen(a), bl = strlen(b); 7 | long long sum = 0; 8 | for (int i = 0; i < al; i++) { 9 | for (int j = 0; j < bl; j++) { 10 | sum += (a[i] - '0') * (b[j] - '0'); 11 | } 12 | } 13 | printf("%lld", sum); 14 | } -------------------------------------------------------------------------------- /Baekjoon/1237.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | printf("문제의 정답"); 4 | } -------------------------------------------------------------------------------- /Baekjoon/1247.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; long long temp; __int128_t S; 7 | for (int t = 0; t < 3; t++) { 8 | cin >> N; S = 0; 9 | for (int i = 0; i < N; i++) { cin >> temp; S += temp; } 10 | if (S > 0) { cout << "+\n"; } 11 | else if (S < 0) { cout << "-\n"; } 12 | else { cout << "0\n"; } 13 | } 14 | } -------------------------------------------------------------------------------- /Baekjoon/1259.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | string s; bool isPalindrome; 7 | while (true) { 8 | cin >> s; 9 | isPalindrome = true; 10 | if (!s.compare("0")) { return 0; } 11 | for (int i = 0; i < s.length() / 2 + 1; i++) { 12 | if (s[i] != s[s.length() - i - 1]) { isPalindrome = false; } 13 | } 14 | cout << (isPalindrome ? "yes" : "no") << '\n'; 15 | } 16 | } -------------------------------------------------------------------------------- /Baekjoon/1267.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | int N, a = 0, b = 0, temp; scanf("%d", &N); 4 | for (int i = 0; i < N; i++) { 5 | scanf("%d", &temp); 6 | a += ((temp / 30) + 1) * 10; 7 | b += ((temp / 60) + 1) * 15; 8 | } 9 | if (a < b) { printf("Y %d", a); } 10 | if (a > b) { printf("M %d", b); } 11 | if (a == b) { printf("Y M %d", a); } 12 | } -------------------------------------------------------------------------------- /Baekjoon/1269.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | unordered_set A, B; int N, M, cnt = 0, temp; 7 | cin >> N >> M; 8 | for (int i = 0; i < N; i++) { 9 | cin >> temp; 10 | A.insert(temp); 11 | } 12 | for (int i = 0; i < M; i++) { 13 | cin >> temp; 14 | if (A.count(temp)) 15 | cnt++; 16 | B.insert(temp); 17 | } 18 | cout << A.size() + B.size() - 2 * cnt; 19 | } -------------------------------------------------------------------------------- /Baekjoon/12738.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; cin >> N; vector D; 7 | for (int i = 0; i < N; i++) { // LIS 8 | int temp; cin >> temp; // O(N * log(N)) 9 | auto it = lower_bound(D.begin(), D.end(), temp); 10 | if (it == D.end()) { 11 | D.push_back(temp); 12 | } else { 13 | *it = temp; 14 | } 15 | } 16 | cout << D.size(); 17 | } -------------------------------------------------------------------------------- /Baekjoon/1292.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int A, B; cin >> A >> B; 7 | int cnt = 0, x = 1, result = 0; 8 | for (int i = 1; i <= B; i++) { 9 | if (A <= i && i <= B) 10 | result += x; 11 | cnt++; 12 | if (x == cnt) { 13 | x++; 14 | cnt = 0; 15 | } 16 | } 17 | cout << result; 18 | } -------------------------------------------------------------------------------- /Baekjoon/1302.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; cin >> N; 7 | string s; int Max = 0; 8 | unordered_map M; 9 | for (int i = 0; i < N; i++) { 10 | cin >> s; 11 | M[s]++; 12 | if (Max <= M[s]) { 13 | Max = M[s]; 14 | } 15 | } 16 | vector temp; 17 | for (auto it: M) 18 | if (it.second == Max) 19 | temp.push_back(it.first); 20 | sort(temp.begin(), temp.end()); 21 | cout << temp[0]; 22 | } -------------------------------------------------------------------------------- /Baekjoon/1305.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int failure(string &S) { 5 | int N = S.size(), j = 0; 6 | vector f(N, 0); 7 | for (int i = 1; i < N; i++) { 8 | while (j > 0 && S[i] != S[j]) 9 | j = f[j - 1]; 10 | if (S[i] == S[j]) 11 | f[i] = ++j; 12 | } 13 | return f[N - 1]; 14 | } 15 | 16 | int main(void) { 17 | ios::sync_with_stdio(false); cin.tie(nullptr); 18 | int L; 19 | string S; 20 | cin >> L >> S; 21 | int f = failure(S); 22 | cout << L - f; 23 | } -------------------------------------------------------------------------------- /Baekjoon/1309.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; int D[N][2] = {}; 7 | D[0][0] = D[0][1] = 1; 8 | for (int i = 1; i < N; i++) { 9 | D[i][0] = (D[i - 1][0] + 2 * D[i - 1][1]) % 9901; 10 | D[i][1] = (D[i - 1][0] + D[i - 1][1]) % 9901; 11 | } 12 | int result = (D[N - 1][0] + 2 * D[N - 1][1]) % 9901; 13 | cout << result; 14 | } -------------------------------------------------------------------------------- /Baekjoon/13163.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; cin >> N; 7 | string s; 8 | getline(cin, s); 9 | while (N--) { 10 | bool god = false; 11 | getline(cin, s); 12 | cout << "god"; 13 | for (auto it : s) { 14 | if (!god && it == ' ') { 15 | god = true; 16 | } else if (god && it != ' ') 17 | cout << it; 18 | } 19 | cout << '\n'; 20 | } 21 | } -------------------------------------------------------------------------------- /Baekjoon/13211.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N, result = 0; cin >> N; 7 | unordered_set u; 8 | string s; 9 | for (int i = 0; i < N; i++) { 10 | cin >> s; u.insert(s); 11 | } 12 | int M; cin >> M; 13 | for (int i = 0; i < M; i++) { 14 | cin >> s; 15 | auto search = u.find(s); 16 | if (search != u.end()) { 17 | result++; 18 | } 19 | } 20 | cout << result; 21 | } -------------------------------------------------------------------------------- /Baekjoon/1322.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N, K, cnt = 0, num = 0; cin >> N >> K; 7 | vector idx; 8 | for (int i = 0; i < 64; i++) { 9 | if (!(N & 1)) { 10 | idx.push_back(num); 11 | } 12 | N >>= 1; 13 | num++; 14 | } 15 | long long result = 0; 16 | while (K > 0) { 17 | if (K & 1) { result += ((long long)1 << idx.at(cnt)); } 18 | cnt++; 19 | K >>= 1; 20 | } 21 | cout << result; 22 | } -------------------------------------------------------------------------------- /Baekjoon/13225.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(void) { 4 | char input[21] = {}; scanf("%s", input); int N = strlen(input); 5 | for (int i = 0; i < N; i++) { 6 | if (input[i] != input[N - i - 1]) { printf("false"); return 0; } 7 | } 8 | printf("true"); 9 | } -------------------------------------------------------------------------------- /Baekjoon/13241.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | long long N, M; 7 | cin >> N >> M; 8 | cout << N * M / __gcd(N, M); 9 | } -------------------------------------------------------------------------------- /Baekjoon/1330.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | int a, b; scanf("%d %d", &a, &b); 4 | if (a > b) { printf(">"); } else if (a == b) { printf("=="); } else { printf("<"); } 5 | } -------------------------------------------------------------------------------- /Baekjoon/13330.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | int N, K, S, Y; scanf("%d %d", &N, &K); 5 | int result = 0; int store[6][2] = {}; 6 | for (int i = 0; i < N; i++) { 7 | scanf("%d %d", &S, &Y); 8 | store[Y - 1][S] += 1; 9 | } 10 | for (int i = 0; i < 6; i++) { 11 | for (int j = 0; j < 2; j++) { 12 | if (store[i][j] != 0) { result += (store[i][j] / K) + (store[i][j] % K != 0); } 13 | } 14 | } 15 | printf("%d", result); 16 | } -------------------------------------------------------------------------------- /Baekjoon/13456.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int T, veclen, sum, temp; cin >> T; 7 | for (int t = 0; t < T; t++) { 8 | cin >> veclen; int vec1[veclen] = {}, vec2[veclen] = {}; 9 | sum = 0; 10 | for (int i = 0; i < veclen; i++) { cin >> vec1[i]; } 11 | for (int i = 0; i < veclen; i++) { cin >> temp; sum += vec1[i] != temp; } 12 | cout << sum << '\n'; 13 | } 14 | } -------------------------------------------------------------------------------- /Baekjoon/13458.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; cin >> N; int A[N] = {}, B, C; 7 | for (int i = 0; i < N; i++) { cin >> A[i]; } 8 | cin >> B >> C; 9 | long long result = N; 10 | for (int i = 0; i < N; i++) { 11 | if (A[i] > B) { 12 | result += (A[i] - B) / C + ((A[i] - B) % C != 0); 13 | } 14 | } 15 | cout << result; 16 | } -------------------------------------------------------------------------------- /Baekjoon/1357.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | inline int Rev(int x) { 5 | string s = to_string(x); 6 | reverse(s.begin(), s.end()); 7 | return stoi(s); 8 | } 9 | 10 | int main(void) { 11 | ios::sync_with_stdio(false); cin.tie(nullptr); 12 | int x, y; cin >> x >> y; 13 | cout << Rev(Rev(x) + Rev(y)); 14 | } -------------------------------------------------------------------------------- /Baekjoon/13610.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int X, Y; cin >> X >> Y; 7 | cout << (1 + X / (Y - X) + (X % (Y - X) != 0)); 8 | } -------------------------------------------------------------------------------- /Baekjoon/13701.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | vector isused(33554433, false); 4 | 5 | int main(void) { 6 | ios::sync_with_stdio(false); cin.tie(NULL); 7 | int temp; 8 | while (!cin.eof()) { 9 | cin >> temp; 10 | if (!isused[temp]) { 11 | cout << temp << ' '; 12 | isused[temp] = true; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Baekjoon/13752.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, temp; cin >> N; 7 | for (int i = 0; i < N; i++) { 8 | cin >> temp; 9 | for (int j = 0; j < temp; j++) { cout << '='; } cout << '\n'; 10 | } 11 | } -------------------------------------------------------------------------------- /Baekjoon/13985.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | string s; 7 | getline(cin, s); 8 | cout << (s[0] + s[4] - '0' == s[8] ? "YES" : "NO"); 9 | } -------------------------------------------------------------------------------- /Baekjoon/14264.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; cin >> N; 7 | cout << fixed << setprecision(15) << (double) N * N * sqrt(3) / 4; 8 | } -------------------------------------------------------------------------------- /Baekjoon/1427.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | string s; cin >> s; sort(s.begin(), s.end(), greater()); 7 | cout << s; 8 | } -------------------------------------------------------------------------------- /Baekjoon/14425.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | unordered_set S; 7 | string s; 8 | int N, M; cin >> N >> M; 9 | for (int i = 0; i < N; i++) { 10 | cin >> s; 11 | S.insert(s); 12 | } 13 | int result = 0; 14 | for (int i = 0; i < M; i++) { 15 | cin >> s; 16 | if (S.count(s)) 17 | result++; 18 | } 19 | cout << result; 20 | } -------------------------------------------------------------------------------- /Baekjoon/14501.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; int T[N + 1] = {}, P[N + 1] = {}; 7 | for (int i = 1; i <= N; i++) { cin >> T[i] >> P[i]; } 8 | int D[N + 2] = {}, Max = 0; 9 | for (int i = 1; i <= N + 1; i++) { 10 | Max = 0; 11 | for (int j = 1; j < i; j++) { 12 | if (T[i - j] <= j) { Max = max(Max, D[i - j] + P[i - j]); } 13 | } 14 | D[i] = max(D[i], Max); 15 | } 16 | cout << D[N + 1]; 17 | } -------------------------------------------------------------------------------- /Baekjoon/14579.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int a, b, result = 1, temp; cin >> a >> b; 7 | for (int i = a; i <= b; i++) { 8 | temp = (i * (i + 1) / 2) % 14579; 9 | result *= temp; result %= 14579; 10 | } 11 | cout << result; 12 | } -------------------------------------------------------------------------------- /Baekjoon/1463.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int D[1000001]; 4 | 5 | int main(void) { 6 | ios::sync_with_stdio(0); cin.tie(0); 7 | int N; cin >> N; 8 | for (int k = 2; k <= N; k++) { 9 | int candidate = D[k - 1] + 1; 10 | if (k % 2 == 0) { candidate = min(candidate, D[k / 2] + 1); } 11 | if (k % 3 == 0) { candidate = min(candidate, D[k / 3] + 1); } 12 | D[k] = candidate; 13 | } 14 | cout << D[N]; 15 | } -------------------------------------------------------------------------------- /Baekjoon/14681.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int x, y; cin >> x >> y; 7 | if (x > 0) { 8 | if (y > 0) { cout << 1; } 9 | else { cout << 4; } 10 | } else { 11 | if (y > 0) { cout << 2; } 12 | else { cout << 3; } 13 | } 14 | } -------------------------------------------------------------------------------- /Baekjoon/1475.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); 6 | cin.tie(0); 7 | string input; 8 | getline(cin, input); 9 | int array[9] = {}; 10 | for (char const &c: input) { 11 | if (c - '0' == 6 || c - '0' == 9) { 12 | array[6]++; 13 | } else { 14 | array[c - '0']++; 15 | } 16 | } 17 | array[6]++; 18 | array[6] /= 2; 19 | cout << *max_element(begin(array), end(array)); 20 | } -------------------------------------------------------------------------------- /Baekjoon/14909.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | int input, result = 0; 5 | while(scanf("%d", &input) != -1) { 6 | if (input > 0) { result++; } 7 | } 8 | printf("%d", result); 9 | } -------------------------------------------------------------------------------- /Baekjoon/14918.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int a, b; cin >> a >> b; cout << a + b; 7 | } -------------------------------------------------------------------------------- /Baekjoon/1500.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int S, K; cin >> S >> K; 7 | int div = S / K; long long result = 1; 8 | for (int i = 0; i < K; i++) { 9 | result *= (long long) (i < S % K ? div + 1 : div); // AM-GM 10 | } 11 | cout << result; 12 | } -------------------------------------------------------------------------------- /Baekjoon/15340.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int call[3] = {30, 35, 40}, data[3] = {40, 30, 20}; 7 | int x, y; 8 | while (true) { 9 | cin >> x >> y; if (x == 0 && y == 0) { return 0; } 10 | int Min = 1 << 30; 11 | for (int i = 0; i < 3; i++) { 12 | Min = min(Min, call[i] * x + data[i] * y); 13 | } 14 | cout << Min << '\n'; 15 | } 16 | } -------------------------------------------------------------------------------- /Baekjoon/1543.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | string s1, s2; getline(cin, s1); getline(cin, s2); 7 | int probe = 0, result = 0; 8 | while (probe < s1.length()) { 9 | if (!s1.compare(probe, s2.length(), s2)) { 10 | result++; 11 | probe += s2.length(); 12 | } else { 13 | probe++; 14 | } 15 | } 16 | cout << result; 17 | } -------------------------------------------------------------------------------- /Baekjoon/15439.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int N; cin >> N; 7 | cout << N * (N - 1); 8 | } -------------------------------------------------------------------------------- /Baekjoon/1546.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int Max = -1, sum = 0, temp, N; cin >> N; 7 | for (int i = 0; i < N; i++) { 8 | cin >> temp; 9 | Max = max(temp, Max); 10 | sum += temp; 11 | } 12 | double result = (double) sum * 100 / (Max * N); 13 | cout << setprecision(5) << result; 14 | } -------------------------------------------------------------------------------- /Baekjoon/1547.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | int T, a, b; int current[3] = {1, 2, 3}; scanf("%d", &T); 4 | for (int i = 0; i < T; i++) { 5 | scanf("%d %d", &a, &b); 6 | if (a == b) { continue; } 7 | int idx1, idx2, temp; 8 | for (int i = 0; i < 3; i++) { if (current[i] == a) { idx1 = i; } if (current[i] == b) {idx2 = i; }} 9 | temp = current[idx1]; current[idx1] = current[idx2]; current[idx2] = temp; 10 | } 11 | printf("%d", current[0]); 12 | } -------------------------------------------------------------------------------- /Baekjoon/1550.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; 7 | cin >> hex >> N; 8 | cout << N; 9 | } -------------------------------------------------------------------------------- /Baekjoon/15552.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(void) { 4 | ios::sync_with_stdio(0); cin.tie(0); 5 | int T; cin >> T; int a, b; 6 | for (int i = 0; i < T; i++) { 7 | cin >> a >> b; 8 | cout << a + b << "\n"; 9 | } 10 | } -------------------------------------------------------------------------------- /Baekjoon/15596.c: -------------------------------------------------------------------------------- 1 | #include 2 | long long sum(int *a, int n) { 3 | long long result = 0; 4 | for (int i = 0; i < n; i++) { 5 | result += *(a + i); 6 | } 7 | return result; 8 | } -------------------------------------------------------------------------------- /Baekjoon/15624.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; int a = 1, b = 0, temp; 7 | while (N--) { 8 | temp = (a + b) % 1000000007; 9 | a = b; 10 | b = temp; 11 | } 12 | cout << b; 13 | } -------------------------------------------------------------------------------- /Baekjoon/15638.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define FIELD 1000000009 4 | 5 | int main(void) { 6 | ios::sync_with_stdio(false); cin.tie(nullptr); 7 | int N; string s; bool isPrime = true; cin >> N >> s; 8 | if (N == 1) { isPrime = false; } 9 | else { 10 | for (int i = 2; i * i <= N; i++) { 11 | if (!(N % i)) { isPrime = false; break; } 12 | } 13 | } 14 | cout << (isPrime ? "Yes" : "No"); 15 | } -------------------------------------------------------------------------------- /Baekjoon/15649.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, m; 4 | bool isused[8]; int arr[8]; 5 | 6 | void backtrack(int k) { 7 | if (k == m) { for (int i = 0; i < m; i++) { cout << arr[i] << " "; } cout << "\n"; return; } 8 | for (int i = 0; i < n; i++) { 9 | if (!isused[i]) { isused[i] = true; arr[k] = i + 1; backtrack(k + 1); isused[i] = false; } 10 | } 11 | } 12 | 13 | int main(void) { 14 | ios::sync_with_stdio(0); cin.tie(0); 15 | int N, M; cin >> N >> M; n = N; m = M; 16 | backtrack(0); 17 | } -------------------------------------------------------------------------------- /Baekjoon/15651.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int m, n; 4 | int arr[8]; 5 | 6 | void backtrack(int k) { 7 | if (m == k) { for(int i = 0; i < m; i++) { cout << arr[i] << " "; } cout << "\n"; return; } 8 | for (int i = 0; i < n; i++) { 9 | arr[k] = i + 1; backtrack(k + 1); 10 | } 11 | } 12 | 13 | int main(void) { 14 | ios::sync_with_stdio(0); cin.tie(0); 15 | int N, M; cin >> N >> M; n = N; m = M; 16 | backtrack(0); 17 | } -------------------------------------------------------------------------------- /Baekjoon/15652.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int n, m; 4 | int arr[8]; 5 | 6 | void backtrack(int k) { 7 | if (k == m) { for (int i = 0; i < m; i++) { cout << arr[i] << " "; } cout << '\n'; return; } 8 | for (int i = (0 < k ? arr[k - 1] - 1: 0); i < n; i++) { 9 | arr[k] = i + 1; backtrack(k + 1); 10 | } 11 | } 12 | 13 | int main(void) { 14 | int N, M; cin >> N >> M; n = N; m = M; 15 | backtrack(0); 16 | } -------------------------------------------------------------------------------- /Baekjoon/15727.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int L; cin >> L; cout << L / 5 + (L % 5 != 0); 7 | } -------------------------------------------------------------------------------- /Baekjoon/15736.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; cout << (int) sqrt(N); 7 | } -------------------------------------------------------------------------------- /Baekjoon/15824.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define FIELD 1000000007 4 | 5 | int main(void) { 6 | ios::sync_with_stdio(false); cin.tie(NULL); 7 | int N; cin >> N; 8 | long long input[N] = {}; 9 | for (int i = 0; i < N; i++) { cin >> input[i]; } 10 | sort(input, input + N); 11 | long long result = 0; 12 | long long weight = 1; 13 | for (int i = 0; i < N; i++) { 14 | long long temp = weight * (input[i] - input[N - i - 1]); 15 | result = (result + temp) % FIELD; 16 | weight = (weight << 1) % FIELD; 17 | } 18 | cout << result; 19 | } -------------------------------------------------------------------------------- /Baekjoon/15829.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define FIELD 1234567891 4 | 5 | int main(void) { 6 | ios::sync_with_stdio(false); cin.tie(nullptr); 7 | long long acc = 1, result = 0; 8 | int N; string s; cin >> N >> s; 9 | for (int i = 0; i < N; i++) { 10 | result += (acc * (s[i] - 'a' + 1)) % FIELD; 11 | result %= FIELD; 12 | acc = acc * 31 % FIELD; 13 | } 14 | cout << result; 15 | } -------------------------------------------------------------------------------- /Baekjoon/15873.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; cin >> N; 7 | if (N < 100) { cout << N % 10 + N / 10; } 8 | else if (N < 1010) { 9 | if (N % 10 == 0) { cout << N % 100 + N / 100; } 10 | else { cout << N % 10 + N / 10; } 11 | } else { cout << 20; } 12 | } -------------------------------------------------------------------------------- /Baekjoon/15894.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | unsigned int N; scanf("%u", &N); 5 | printf("%u", N << 2); 6 | } -------------------------------------------------------------------------------- /Baekjoon/15964.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | long long A, B; cin >> A >> B; 7 | cout << (A + B) * (A - B); 8 | } -------------------------------------------------------------------------------- /Baekjoon/15969.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int N, temp, Min = 1001, Max = -1; cin >> N; 7 | for (int i = 0; i < N; i++) { 8 | cin >> temp; 9 | Min = min(Min, temp); 10 | Max = max(Max, temp); 11 | } 12 | cout << Max - Min; 13 | } -------------------------------------------------------------------------------- /Baekjoon/15988.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define FIELD 1000000009 4 | 5 | int main(void) { 6 | ios::sync_with_stdio(false); cin.tie(nullptr); 7 | int N, T; cin >> T; 8 | int D[1000000] = {1, 2, 4, }; 9 | for (int i = 3; i < 1000000; i++) { 10 | D[i] = ((D[i - 1] + D[i - 2]) % FIELD + D[i - 3]) % FIELD; 11 | } 12 | while (T--) { 13 | cin >> N; 14 | cout << D[N - 1] << '\n'; 15 | } 16 | } -------------------------------------------------------------------------------- /Baekjoon/1629.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | __int128_t power(__int128_t a, __int128_t b, __int128_t c) { 5 | if (c == 1) { return 0; } 6 | if (b == 0) { return 1; } 7 | long temp = power(a, b / 2, c); 8 | if (b % 2 == 0) { 9 | return temp * temp % c; 10 | } else { 11 | return temp * temp * a % c; 12 | } 13 | } 14 | 15 | int main(void) { 16 | ios::sync_with_stdio(0); cin.tie(0); 17 | long A, B, C; cin >> A >> B >> C; 18 | cout << (long long) (power(A, B, C) % C); 19 | } -------------------------------------------------------------------------------- /Baekjoon/16396.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, x, y, temp; cin >> N; bool Map[10000] = {}; 7 | for (int i = 0; i < N; i++) { 8 | cin >> x >> y; 9 | if (x > y) { temp = x; x = y; y = temp; } 10 | for (int j = x; j < y; j++) { 11 | if (!Map[j]) { Map[j] = true; } 12 | } 13 | } 14 | int result = 0; 15 | for (int i = 1; i <= 9999; i++) { 16 | if (Map[i]) { result++; } 17 | } // O(n ** 2) 18 | cout << result; 19 | } -------------------------------------------------------------------------------- /Baekjoon/16430.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int A, B; 7 | cin >> A >> B; 8 | int gcd = __gcd(B - A, B); 9 | cout << (B - A) / gcd << ' ' << B / gcd; 10 | } -------------------------------------------------------------------------------- /Baekjoon/16480.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | long long R, r; scanf("%lld %lld", &R, &r); 5 | printf("%lld", R * R - 2 * R * r); 6 | } -------------------------------------------------------------------------------- /Baekjoon/16561.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; 7 | cout << (N / 3 - 1) * (N / 3 - 2) / 2; 8 | } -------------------------------------------------------------------------------- /Baekjoon/1676.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, temp, result = 0; cin >> N; 7 | for (int i = 1; i <= N; i++) { 8 | if (i % 5 == 0) { 9 | temp = i; 10 | while (temp % 5 == 0) { result++; temp /= 5; } 11 | } 12 | } 13 | cout << result; 14 | } -------------------------------------------------------------------------------- /Baekjoon/1699.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, Min; cin >> N; int D[N + 1] = {}; 7 | for (int i = 1; i <= N; i++) { 8 | int root = floor(sqrt(i)); 9 | if (root * root == i) { D[i] = 1; continue; } 10 | Min = 1 << 30; 11 | for (int j = 1; j <= root; j++) { 12 | Min = min(Min, D[i - j * j] + 1); 13 | } 14 | D[i] = Min; 15 | } 16 | cout << D[N]; 17 | } -------------------------------------------------------------------------------- /Baekjoon/17009.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int A, B, x, y, z; 7 | cin >> x >> y >> z; 8 | A = 3 * x + 2 * y + z; 9 | cin >> x >> y >> z; 10 | B = 3 * x + 2 * y + z; 11 | if (A > B) { cout << 'A'; } 12 | else if (A < B) { cout << 'B'; } 13 | else { cout << 'T'; } 14 | } -------------------------------------------------------------------------------- /Baekjoon/17118.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # xp == a * x0 + b (mod p) by diagonalization 3 | # p | a * x0 + b - xp = 998244359987710471 = 998244353 * 1000000007 4 | x0 = gets.to_i 5 | a = 860798509 6 | b = 198609463 7 | p = 1000000007 8 | xp = (a * x0 + b) % p 9 | print xp 10 | -------------------------------------------------------------------------------- /Baekjoon/1712.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int A, B, C, result; cin >> A >> B >> C; 7 | if (C <= B) { result = -1; } 8 | else { 9 | result = A / (C - B) + 1; 10 | } 11 | cout << result; 12 | } -------------------------------------------------------------------------------- /Baekjoon/17173.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, M, sum = 0; cin >> N >> M; 7 | int input[M] = {}; for (int i = 0; i < M; i++) { cin >> input[i]; } 8 | for (int i = 1; i <= N; i++) { 9 | for (int j = 0; j < M; j++) { 10 | if (i % input[j] == 0) { sum += i; break; } 11 | } 12 | } 13 | cout << sum; 14 | } -------------------------------------------------------------------------------- /Baekjoon/1718.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int main(void) { 6 | ios::sync_with_stdio(0); cin.tie(0); 7 | string temp; getline(cin, temp); string key; 8 | char *pt = (char *)temp.c_str(); cin >> key; // Vigenere Cipher 9 | // Can reduce space complexity by O(len(key)) but who cares 10 | int keylen = key.length(); string ct; 11 | for (int i = 0; i < temp.length(); i++) { 12 | if (pt[i] == ' ') { ct += ' '; } 13 | else { 14 | ct += (pt[i] - key[i % key.length()] - 1 + 26) % 26 + 'a'; 15 | } 16 | } 17 | cout << ct; 18 | } -------------------------------------------------------------------------------- /Baekjoon/17206.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int T, temp, x, y, z, result; cin >> T; 7 | for (int t = 0; t < T; t++) { 8 | cin >> temp; x = temp / 3; y = temp / 7; z = temp / 21; 9 | result = 3 * x * (x + 1) / 2; 10 | result += 7 * y * (y + 1) / 2; 11 | result -= 21 * z * (z + 1) / 2; 12 | cout << result << '\n'; 13 | } 14 | } -------------------------------------------------------------------------------- /Baekjoon/17252.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int N; cin >> N; 7 | if (N == 0) { cout << "NO"; return 0; } 8 | while (N > 0) { 9 | if (N % 3 == 2) { 10 | cout << "NO"; 11 | return 0; 12 | } 13 | N /= 3; 14 | } 15 | cout << "YES"; 16 | } -------------------------------------------------------------------------------- /Baekjoon/17253.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | long long N; cin >> N; 7 | if (N == 0) { cout << "NO"; return 0; } 8 | while (N > 0) { 9 | if (N % 3 == 2) { 10 | cout << "NO"; 11 | return 0; 12 | } 13 | N /= 3; 14 | } 15 | cout << "YES"; 16 | } -------------------------------------------------------------------------------- /Baekjoon/1735.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int a, b, c, d; cin >> a >> b >> c >> d; 7 | int numerator = a * d + b * c; 8 | int denominator = b * d; 9 | int gcd = __gcd(numerator, denominator); 10 | cout << numerator / gcd << ' ' << denominator / gcd; 11 | } -------------------------------------------------------------------------------- /Baekjoon/17390.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int N, Q, L, R; 7 | cin >> N >> Q; 8 | int input[N] = {}, acc[N + 1] = {}; 9 | for (int i = 0; i < N; i++) { cin >> input[i]; } 10 | sort(input, input + N); 11 | for (int i = 0; i < N; i++) { 12 | acc[i + 1] = acc[i] + input[i]; 13 | } 14 | while (Q--) { 15 | cin >> L >> R; 16 | cout << acc[R] - acc[L - 1] << '\n'; 17 | } 18 | } -------------------------------------------------------------------------------- /Baekjoon/1740.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | long long N, result = 0, weight = 1; cin >> N; 7 | while (N > 0) { 8 | result += (N & 1) * weight; 9 | N >>= 1; 10 | weight *= 3; 11 | } 12 | cout << result; 13 | } -------------------------------------------------------------------------------- /Baekjoon/17466.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | long long N, P; 7 | cin >> N >> P; 8 | long long result = 1; 9 | for (int i = 1; i <= N; i++) { 10 | result = (result * i) % P; 11 | } 12 | cout << result; 13 | } -------------------------------------------------------------------------------- /Baekjoon/1789.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | long long N; 7 | cin >> N; 8 | int n = (-1 + static_cast(sqrt(1 + 8 * N))) / 2; 9 | cout << n; 10 | } -------------------------------------------------------------------------------- /Baekjoon/18017.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | long double a, b; cin >> a >> b; long double c = 299792458.0; 7 | cout.precision(19); 8 | cout << (a + b) / (1 + a * b / (c * c)); 9 | } -------------------------------------------------------------------------------- /Baekjoon/18408.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int temp, out = 0; 7 | for (int i = 0; i < 3; i++) { 8 | cin >> temp; out += temp == 1; 9 | } 10 | int result = out > (3 - out) ? 1 : 2; 11 | cout << result; 12 | } -------------------------------------------------------------------------------- /Baekjoon/1904.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; 7 | int D[N] = {}; D[0] = 1; D[1] = 2; 8 | for (int i = 2; i < N; i++) { 9 | D[i] = (D[i - 1] + D[i - 2]) % 15746; 10 | } 11 | cout << D[N - 1]; 12 | } -------------------------------------------------------------------------------- /Baekjoon/1912.c: -------------------------------------------------------------------------------- 1 | #include 2 | int input[100001]; 3 | int D[100001]; 4 | int max(int a, int b) { 5 | return a > b ? a : b; 6 | } 7 | 8 | int main() { 9 | int N; scanf("%d", &N); 10 | for (int i = 1; i <= N; i++) { 11 | scanf("%d", &input[i]); 12 | } 13 | D[1] = input[1]; int result = D[1]; 14 | for (int k = 2; k <= N; k++) { 15 | D[k] = max(0, D[k - 1]) + input[k]; 16 | if (result < D[k]) { result = D[k]; } 17 | } 18 | printf("%d", result); 19 | } -------------------------------------------------------------------------------- /Baekjoon/1919.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | char a[1003] = {}, b[1003] = {}; 3 | scanf("%s %s", &a, &b); 4 | int al = strlen(a), bl = strlen(b); 5 | int visited[1003] = {}; 6 | int cnt = 0; 7 | for (int i = 0; i < al; i++) { 8 | for (int j = 0; j < bl; j++) { 9 | if (a[i] == b[j] && visited[j] == 0) { 10 | cnt++; visited[j] = 1; break; 11 | } 12 | } 13 | } 14 | printf("%d", al + bl - cnt * 2); 15 | } -------------------------------------------------------------------------------- /Baekjoon/1924.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | bool is31[12] = {true, false, true, false, true, false, true, true, false, true, false, true}; 7 | string Day[7] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"}; 8 | int x, y, acc = 0; cin >> x >> y; acc = --y; 9 | for (int i = 1; i < x; i++) { 10 | acc += (i == 2 ? 28 : (is31[i - 1] ? 31 : 30)); 11 | } 12 | cout << Day[acc % 7]; 13 | } -------------------------------------------------------------------------------- /Baekjoon/1927.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | priority_queue, greater> PQ; 7 | int N, temp; cin >> N; 8 | for (int i = 0; i < N; i++) { 9 | cin >> temp; 10 | if (temp == 0) { 11 | if (PQ.empty()) { cout << "0\n"; } 12 | else { cout << PQ.top() << '\n'; PQ.pop(); } 13 | } else { PQ.push(temp); } 14 | } 15 | } -------------------------------------------------------------------------------- /Baekjoon/1929.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int M, N; cin >> M >> N; 7 | vector isPrime(N + 1, true); 8 | isPrime[1] = false; 9 | for (int i = 2; i * i <= N; i++) { 10 | if (!isPrime[i]) { continue; } 11 | for (int j = i * i; j <= N; j += i) { isPrime[j] = false; } 12 | } 13 | for (int i = M; i <= N; i++) { 14 | if (isPrime[i]) { cout << i << '\n'; } 15 | } 16 | } -------------------------------------------------------------------------------- /Baekjoon/1934.c: -------------------------------------------------------------------------------- 1 | #include 2 | int gcd(int a, int b) { 3 | if (b == 0) { return a; } 4 | return gcd(b, a % b); 5 | } 6 | 7 | int main(void) { 8 | int T, result, a, b; scanf("%d", &T); 9 | for (int i = 0; i < T; i++) { 10 | scanf("%d %d", &a, &b); 11 | if (a < b) { int temp = b; b = a; a = temp;} 12 | result = gcd(a, b); 13 | printf("%d\n", a * b / result); 14 | } 15 | } -------------------------------------------------------------------------------- /Baekjoon/19532.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int a, b, c, d, e, f; 7 | cin >> a >> b >> c >> d >> e >> f; 8 | int D = a * e - b * d; 9 | int x = (e * c - b * f) / D; 10 | int y = (a * f - c * d) / D; 11 | cout << x << ' ' << y; 12 | } -------------------------------------------------------------------------------- /Baekjoon/19539.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; cin >> N; 7 | int target[N]; 8 | int cnt = 0, total = 0; 9 | for (int i = 0; i < N; i++) { 10 | cin >> target[i]; 11 | total += target[i]; 12 | cnt += target[i] / 2; 13 | } 14 | if (total % 3 != 0) { 15 | cout << "NO"; 16 | return 0; 17 | } 18 | cout << (total / 3 <= cnt ? "YES" : "NO"); 19 | } -------------------------------------------------------------------------------- /Baekjoon/1964.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | long long N; cin >> N; 7 | long long result = 5 + 7 * (N - 1) + 3 * (N - 1) * (N - 2) / 2; 8 | cout << result % 45678; 9 | } -------------------------------------------------------------------------------- /Baekjoon/1965.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; int input[N] = {}, Max = -1; int D[N] = {}; 7 | for (int i = 0; i < N; i++) { cin >> input[i]; } 8 | for (int i = 0; i < N; i++) { 9 | for (int j = i - 1; j >= 0; j--) { 10 | if (input[j] < input[i]) { D[i] = max(D[i], D[j]); } 11 | } 12 | D[i] += 1; 13 | if (Max < D[i]) { Max = D[i]; } 14 | } 15 | cout << Max; 16 | } -------------------------------------------------------------------------------- /Baekjoon/1977.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | inline int isSquare(int x) { 5 | int root = (int)sqrt(x); 6 | return root * root == x; 7 | } 8 | 9 | int main(void) { 10 | ios::sync_with_stdio(false); cin.tie(nullptr); 11 | int M, N; cin >> M >> N; int Min; bool found = false; 12 | int sum = 0; 13 | for (int i = M; i <= N; i++) { 14 | if (isSquare(i)) { 15 | if (!found) { found = true; Min = i; } 16 | sum += i; 17 | } 18 | } 19 | if (found) { cout << sum << '\n' << Min; } 20 | else { cout << -1; } 21 | } -------------------------------------------------------------------------------- /Baekjoon/2003.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, M; cin >> N >> M; int input[N]; 7 | for (int i = 0; i < N; i++) { cin >> input[i]; } 8 | int p1 = 0, p2 = 0, result = 0, sum = 0; 9 | while (p1 < N) { // O(n) 10 | if (sum < M) { sum += input[p2++]; } 11 | else { 12 | if (sum == M) { result++; } 13 | sum -= input[p1++]; 14 | } 15 | } 16 | cout << result; 17 | } -------------------------------------------------------------------------------- /Baekjoon/2004.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int div_n(int num, int n) { 5 | int result = 0; 6 | while (num) { 7 | result += num / n; 8 | num /= n; 9 | } 10 | return result; 11 | } 12 | 13 | int main(void) { 14 | ios::sync_with_stdio(0); cin.tie(0); 15 | int N, M; cin >> N >> M; 16 | int num5 = div_n(N, 5) - div_n(M, 5) - div_n(N - M, 5); 17 | int num2 = div_n(N, 2) - div_n(M, 2) - div_n(N - M, 2); 18 | cout << (num2 ? min(num2, num5) : 0); 19 | } -------------------------------------------------------------------------------- /Baekjoon/2010.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, temp, result = 0; cin >> N; 7 | for (int i = 0; i < N; i++) { 8 | cin >> temp; 9 | if (i == 0) { result = temp; } 10 | else { result = result - 1 + temp; } 11 | } 12 | cout << result; 13 | } -------------------------------------------------------------------------------- /Baekjoon/2012.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int N; cin >> N; int score[N + 1] = {}; 7 | for (int i = 1; i <= N; i++) { cin >> score[i]; } 8 | sort(score + 1, score + N + 1); 9 | long long sum = 0; 10 | for (int i = 1; i <= N; i++) { 11 | sum += (long long)abs(i - score[i]); 12 | } 13 | cout << sum; 14 | } -------------------------------------------------------------------------------- /Baekjoon/2075.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; int input[N * N] = {}; 7 | for (int i = 0; i < N * N; i++) { cin >> input[i]; } 8 | sort(input, input + N * N); // O(n * log (n)) 9 | cout << input[N * N - N]; 10 | // Using priority queue: O(n * log (n)) 11 | } -------------------------------------------------------------------------------- /Baekjoon/2133.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; int D[N + 1] = {}; D[2] = 3; 7 | if (N < 4) { cout << D[N]; return 0; } 8 | for (int i = 4; i <= N; i += 2) { 9 | D[i] = 3 * D[i - 2] + 2; 10 | for (int j = i - 4; j >= 2; j -= 2) 11 | D[i] += 2 * D[j]; 12 | } 13 | cout << D[N]; 14 | } -------------------------------------------------------------------------------- /Baekjoon/2164.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; queue Q; 7 | for (int i = 1; i <= N; i++) { Q.push(i); } 8 | for (int i = 0; i < N - 1; i++) { 9 | Q.pop(); auto current = Q.front(); Q.pop(); Q.push(current); 10 | } 11 | cout << Q.front(); 12 | } -------------------------------------------------------------------------------- /Baekjoon/2166.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, x, y; cin >> N; pair points[N]; 7 | for (int i = 0; i < N; i++) { 8 | cin >> x >> y; points[i] = {x, y}; 9 | } 10 | double A = 0; 11 | for (int i = 0; i < N; i++) { // Green Theorem 12 | auto p1 = points[i], p2 = points[(i + 1) % N]; 13 | A += p2.first * p1.second - p1.first * p2.second; 14 | } 15 | cout << fixed << setprecision(1) << abs(A) / 2; 16 | } -------------------------------------------------------------------------------- /Baekjoon/2168.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int a, b; cin >> a >> b; 7 | int gcd = __gcd(a, b); 8 | int A = a / gcd, B = b / gcd; 9 | cout << (long long)gcd * (A + B - 1); 10 | } -------------------------------------------------------------------------------- /Baekjoon/2193.c: -------------------------------------------------------------------------------- 1 | #include 2 | unsigned long D[91][2]; 3 | 4 | int main(void) { 5 | int N; scanf("%d", &N); 6 | D[1][0] = 0; D[1][1] = 1; 7 | for (int i = 2; i <= N; i++) { 8 | D[i][0] = D[i - 1][0] + D[i - 1][1]; 9 | D[i][1] = D[i - 1][0]; 10 | } 11 | printf("%lu", D[N][0] + D[N][1]); 12 | } -------------------------------------------------------------------------------- /Baekjoon/2217.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N, Max = -1; cin >> N; short input[N] = {}; 7 | for (int i = 0; i < N; i++) { cin >> input[i]; } 8 | sort(input, input + N, greater()); 9 | // Or we can just use counting sort 10 | for (int i = 0; i < N; i++) { 11 | if (Max < (i + 1) * input[i]) { Max = (i + 1) * input[i]; } 12 | } 13 | cout << Max; 14 | } -------------------------------------------------------------------------------- /Baekjoon/2225.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, K; cin >> N >> K; 7 | int D[N + K][N + K] = {}; // {n + k - 1} \choose {n} 8 | D[0][0] = 1; 9 | for (int i = 1; i <= N + K - 1; i++) { 10 | D[i][0] = D[i][i] = 1; 11 | for (int j = 1; j <= i - 1; j++) { 12 | D[i][j] = (D[i - 1][j - 1] + D[i - 1][j]) % 1000000000; 13 | } 14 | } 15 | cout << D[N + K - 1][N]; 16 | } -------------------------------------------------------------------------------- /Baekjoon/2226.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | N = int(input()) - 1 3 | a = 0 4 | for i in range(N): 5 | a = (1 << i) - a 6 | print(a) -------------------------------------------------------------------------------- /Baekjoon/2294.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define INF 1 << 30 4 | 5 | int main(void) { 6 | ios::sync_with_stdio(0); cin.tie(0); 7 | int N, K; cin >> N >> K; int A[N] = {}; 8 | for (int i = 0; i < N; i++) { cin >> A[i]; } 9 | int D[K + 1] = {}; 10 | fill(D, D + K + 1, INF); 11 | D[0] = 0; 12 | for (int i = 0; i < N; i++) 13 | for (int j = A[i]; j <= K; j++) 14 | D[j] = min(D[j], D[j - A[i]] + 1); 15 | cout << (D[K] == INF ? -1 : D[K]); 16 | } -------------------------------------------------------------------------------- /Baekjoon/2352.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, Max = 0; cin >> N; 7 | vector D; D.push_back(-1); int temp; // LIS O(N * log(N)) 8 | for (int i = 1; i <= N; i++) { 9 | cin >> temp; 10 | if (D.back() < temp) { D.push_back(temp); Max++; } 11 | else { *lower_bound(D.begin(), D.end(), temp) = temp; } 12 | } 13 | cout << Max; 14 | } -------------------------------------------------------------------------------- /Baekjoon/2355.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | long long A, B; cin >> A >> B; 7 | if (A > B) swap(A, B); 8 | __int128_t result = 0; 9 | result += (__int128_t) (B - A + 1) * A; 10 | result += (__int128_t) (B - A) * (B - A + 1) / 2; 11 | cout << (long long)result; 12 | } -------------------------------------------------------------------------------- /Baekjoon/2381.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N, x, y; cin >> N; 7 | int addMax = -(1 << 30), addMin = 1 << 30, subMax = -(1 << 30), subMin = 1 << 30; 8 | for (int i = 0; i < N; i++) { 9 | cin >> x >> y; 10 | addMax = max(addMax, x + y); 11 | addMin = min(addMin, x + y); 12 | subMax = max(subMax, x - y); 13 | subMin = min(subMin, x - y); 14 | } 15 | cout << max(addMax - addMin, subMax - subMin); 16 | } -------------------------------------------------------------------------------- /Baekjoon/2399.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | long long N; cin >> N; int input[N] = {}; 7 | for (int i = 0; i < N; i++) { cin >> input[i]; } 8 | sort(input, input + N); long long result = 0; 9 | for (long long i = 1; i < N; i++) { 10 | result += (input[i] - input[i - 1]) * (N - i) * i; 11 | } 12 | cout << (result << 1); 13 | } -------------------------------------------------------------------------------- /Baekjoon/2405.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; cin >> N; int input[N] = {}; 7 | for (int i = 0; i < N; i++) { cin >> input[i]; } 8 | sort(input, input + N); 9 | int Max = -(1 << 30), Min = 1 << 30; 10 | for (int i = 1; i < N - 1; i++) { 11 | Max = max(Max, 3 * input[i] - input[i] - input[i + 1] - input[0]); 12 | Min = min(Min, 3 * input[i] - input[i] - input[i - 1] - input[N - 1]); 13 | } 14 | cout << max(abs(Max), abs(Min)); 15 | } -------------------------------------------------------------------------------- /Baekjoon/2410.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; cin >> N; int D[N + 1] = {}; 7 | if (N == 1) { cout << 1; return 0; } 8 | D[1] = 1; D[2] = 2; 9 | for (int i = 3; i <= N; i++) { 10 | D[i] = (D[i - 1] + (i % 2 ? 0 : D[i / 2])) % 1000000000; 11 | } 12 | cout << D[N]; 13 | } -------------------------------------------------------------------------------- /Baekjoon/2420.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | long long N, M; 7 | cin >> N >> M; 8 | cout << abs(N - M); 9 | } -------------------------------------------------------------------------------- /Baekjoon/2475.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | int sum = 0, temp; for (int i = 0; i < 5; i++) { scanf("%d", &temp); sum += temp * temp; } 4 | printf("%d", sum % 10); 5 | } -------------------------------------------------------------------------------- /Baekjoon/2480.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | int a, b, c; scanf("%d %d %d", &a, &b, &c); 4 | int result = 0; 5 | if (a == b && b == c) { 6 | result = 10000 + a * 1000; 7 | } else if (a == b) { 8 | result = 1000 + a * 100; 9 | } else if (b == c) { 10 | result = 1000 + b * 100; 11 | } else if (a == c) { 12 | result = 1000 + c * 100; 13 | } else { 14 | int temp = a > b ? a : b; 15 | result = 100 * (temp > c ? temp : c); 16 | } 17 | printf("%d\n", result); 18 | } -------------------------------------------------------------------------------- /Baekjoon/2490.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | char map[5] = {'D', 'C', 'B', 'A', 'E'}; 4 | int cnt = 0; 5 | for (int i = 0; i < 3; i++) { 6 | int input[4] = {}; scanf("%d %d %d %d", &input[0], &input[1], &input[2], &input[3]); 7 | printf("%c\n", map[input[0] + input[1] + input[2] + input[3]]); 8 | } 9 | } -------------------------------------------------------------------------------- /Baekjoon/2501.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, K, cnt = 0; cin >> N >> K; 7 | for (int i = 1; i <= N; i++) { 8 | if (N % i == 0) { cnt++; if (cnt == K) { cout << i; return 0; } } 9 | } 10 | cout << 0; 11 | } -------------------------------------------------------------------------------- /Baekjoon/2502.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int D, K; cin >> D >> K; 7 | int x = 1, y = 1; 8 | for (int i = 0; i < D - 3; i++) { 9 | int temp = x + y; 10 | x = y; 11 | y = temp; 12 | } 13 | for (int i = 1; x * i <= K; i++) { 14 | if ((K - x * i) % y == 0) { 15 | cout << i << '\n' << (K - x * i) / y; 16 | return 0; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Baekjoon/2522.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | int N; scanf("%d", &N); 5 | for (int i = 0; i < N; i++) { 6 | for (int j = 0; j < N - i - 1; j++) { printf(" "); } 7 | for (int j = 0; j <= i; j++ ) { printf("*"); } 8 | printf("\n"); 9 | } 10 | for (int i = N - 2; i >= 0; i--) { 11 | for (int j = 0; j < N - i - 1; j++) { printf(" "); } 12 | for (int j = 0; j <= i; j++ ) { printf("*"); } 13 | printf("\n"); 14 | } 15 | } -------------------------------------------------------------------------------- /Baekjoon/2523.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | int N; scanf("%d", &N); 5 | for (int i = 0; i < N; i++) { 6 | for (int j = 0; j <= i; j++ ) { printf("*"); } 7 | printf("\n"); 8 | } 9 | for (int i = N - 2; i >= 0; i--) { 10 | for (int j = 0; j <= i; j++ ) { printf("*"); } 11 | printf("\n"); 12 | } 13 | } -------------------------------------------------------------------------------- /Baekjoon/2530.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int h, m, s, t; cin >> h >> m >> s >> t; 7 | int hd = t / 3600; 8 | int md = (t - hd * 3600) / 60; 9 | int sd = (t - hd * 3600 - md * 60); 10 | cout << (h + hd + (m + md + (s + sd) / 60) / 60) % 24 << ' '; 11 | cout << (m + md + (s + sd) / 60) % 60 << ' '; 12 | cout << (s + sd) % 60; 13 | } -------------------------------------------------------------------------------- /Baekjoon/2556.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | int N; scanf("%d", &N); 4 | for (int i = 0; i < N; i++) { 5 | for (int j = 0; j < N; j++) { 6 | if (i == 0 || i == N - 1) { printf("*"); } 7 | else if (j == 0 || j == N - 1) { printf("*"); } 8 | else { printf(" "); } 9 | } 10 | printf("\n"); 11 | } 12 | } -------------------------------------------------------------------------------- /Baekjoon/2556.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int N; cin >> N; 7 | for (int i = 0; i < N; i++) { 8 | for (int j = 0; j < N; j++) { 9 | cout << '*'; 10 | } 11 | cout << '\n'; 12 | } 13 | } -------------------------------------------------------------------------------- /Baekjoon/2558.c: -------------------------------------------------------------------------------- 1 | main(){int N,M;scanf("%d %d",&N,&M);printf("%d\n",N+M);} -------------------------------------------------------------------------------- /Baekjoon/2559.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int N, K; cin >> N >> K; 7 | int temp, Max = -(1 << 30); int acc[N + 1] = {}; 8 | for (int i = 0; i < N; i++) { 9 | cin >> temp; 10 | acc[i + 1] = acc[i] + temp; 11 | if (i >= K) { 12 | Max = max(Max, acc[i] - acc[i - K]); 13 | } 14 | } 15 | Max = max(Max, acc[N] - acc[N - K]); 16 | cout << Max; 17 | } -------------------------------------------------------------------------------- /Baekjoon/2562.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(void) { 4 | ios::sync_with_stdio(0); cin.tie(0); 5 | int max = 0, cnt = 0, temp = 0; 6 | for (int i = 0; i < 9; i++) { 7 | cin >> temp; if (temp > max) {max = temp; cnt = i; } 8 | } 9 | cout << max << "\n" << cnt + 1; 10 | } -------------------------------------------------------------------------------- /Baekjoon/2566.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | int max = -1, temp, x, y; 4 | for (int i = 0; i < 9; i++) { 5 | for (int j = 0; j < 9; j++) { 6 | scanf("%d", &temp); 7 | if (temp > max) { max = temp; x = i; y = j; } 8 | } 9 | } 10 | printf("%d\n%d %d", max, x + 1, y + 1); 11 | } -------------------------------------------------------------------------------- /Baekjoon/2576.c: -------------------------------------------------------------------------------- 1 | int main(){ 2 | int sum = 0, min = 100, temp = 0; 3 | for (int i = 0; i < 7; i++) { 4 | scanf("%d", &temp); 5 | if (temp % 2 == 1) { 6 | sum += temp; 7 | if (min > temp) { min = temp; } 8 | } 9 | } 10 | if (sum == 0) { printf("-1"); } 11 | else { printf("%d\n%d", sum, min); } 12 | } -------------------------------------------------------------------------------- /Baekjoon/2577.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); 6 | cin.tie(0); 7 | string buffer; 8 | int output = 1; 9 | short array[10] = {}; 10 | for(int i = 0; i < 3; i++) { 11 | getline(cin, buffer); 12 | output *= stoi(buffer); 13 | } 14 | string s = to_string(output); 15 | for (char const &c: s) { 16 | array[c - '0']++; 17 | } 18 | for (int i = 0; i < 10; i++) { 19 | cout << array[i]; 20 | if (i != 9) 21 | cout << '\n'; 22 | } 23 | } -------------------------------------------------------------------------------- /Baekjoon/2587.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(void) { 4 | ios::sync_with_stdio(0); cin.tie(0); 5 | int input[5]; int sum = 0; for (int i = 0; i < 5; i++) { cin >> input[i]; sum += input[i]; } 6 | sort(input, input + 5); 7 | cout << (sum / 5) << "\n" << input[2]; 8 | } -------------------------------------------------------------------------------- /Baekjoon/2588.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | int a, b, temp, b1; scanf("%d %d", &a, &b); b1 = b; 4 | for (int i = 0; i < 3; i++) { 5 | temp = b % 10; printf("%d\n", a * temp); 6 | b = (b - temp) / 10; 7 | } 8 | printf("%d", a * b1); 9 | } -------------------------------------------------------------------------------- /Baekjoon/2609.c: -------------------------------------------------------------------------------- 1 | #include 2 | int gcd(int a, int b) { 3 | if (b == 0) { return a; } 4 | return gcd(b, a % b); 5 | } 6 | 7 | int main(void) { 8 | int a, b; scanf("%d %d", &a, &b); 9 | if (a < b) { int temp = b; b = a; a = temp;} 10 | int result = gcd(a, b); 11 | printf("%d\n%d", result, a * b / result); 12 | } -------------------------------------------------------------------------------- /Baekjoon/2631.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, result = 0; cin >> N; int input[N] = {}; 7 | for (int i = 0; i < N; i++) { cin >> input[i]; } 8 | int D[N] = {}; 9 | for (int i = 0; i < N; i++) { 10 | for (int j = i; j >= 0; j--) { 11 | if (input[i] > input[j]) { 12 | D[i] = max(D[i], D[j]); 13 | } 14 | } 15 | D[i]++; 16 | result = max(D[i], result); 17 | } 18 | cout << N - result; 19 | } -------------------------------------------------------------------------------- /Baekjoon/2675.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | int T; scanf("%d", &T); 4 | for (int i = 0; i < T; i++) { 5 | int num; char input[21] = {}; 6 | scanf("%d %s", &num, &input); 7 | for (int j = 0; j < 21; j++) { 8 | if (input[j] == 0) { break;} 9 | for (int k = 0; k < num; k++) { 10 | printf("%c", input[j]); 11 | } 12 | } 13 | printf("\n"); 14 | } 15 | } -------------------------------------------------------------------------------- /Baekjoon/2702.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int T, a, b; cin >> T; 7 | for (int i = 0; i < T; i++) { 8 | cin >> a >> b; int gcd = __gcd(a, b); 9 | cout << a * b / gcd << ' ' << gcd << '\n'; 10 | } 11 | } -------------------------------------------------------------------------------- /Baekjoon/2738.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N, M, temp; cin >> N >> M; int input[N][M] = {}; 7 | for (int i = 0; i < N; i++) { 8 | for (int j = 0; j < M; j++) { 9 | cin >> input[i][j]; 10 | } 11 | } 12 | for (int i = 0; i < N; i++) { 13 | for (int j = 0; j < M; j++) { 14 | cin >> temp; cout << input[i][j] + temp; 15 | if (j != M) { cout << ' '; } 16 | } 17 | cout << '\n'; 18 | } 19 | } -------------------------------------------------------------------------------- /Baekjoon/2739.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; 7 | for (int i = 1; i < 10; i++) { 8 | cout << N << " * " << i << " = " << N * i << "\n"; 9 | } 10 | } -------------------------------------------------------------------------------- /Baekjoon/2741.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(void) { 4 | ios::sync_with_stdio(0); cin.tie(0); 5 | int N; cin >> N; 6 | for (int i = 1; i < N + 1; i++) { 7 | cout << i << "\n"; 8 | } 9 | } -------------------------------------------------------------------------------- /Baekjoon/2742.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(void) { 4 | ios::sync_with_stdio(0); cin.tie(0); 5 | int N; cin >> N; 6 | for (int i = N; i >= 1; i--) { cout << i << '\n';} 7 | } -------------------------------------------------------------------------------- /Baekjoon/2743.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | char input[101] = {}; scanf("%s", input); 4 | printf("%d", strlen(input)); 5 | } -------------------------------------------------------------------------------- /Baekjoon/2750.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | int N; scanf("%d", &N); int input[1000]; 5 | for (int i = 0; i < N; i++) { 6 | scanf("%d", &input[i]); 7 | } 8 | // Bubble sort 9 | for (int i = 0; i < N; i++) { 10 | for (int j = 0; j < i; j++) { 11 | if (input[j] > input[i]) { 12 | register int temp = input[i]; input[i] = input[j]; input[j] = temp; 13 | } 14 | } 15 | } 16 | for (int i = 0; i < N; i++) { 17 | printf("%d\n", input[i]); 18 | } 19 | } -------------------------------------------------------------------------------- /Baekjoon/2752.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int x, y, z; cin >> x >> y >> z; 5 | int a = min(x, min(y, z)); 6 | int b = max(x, max(y, z)); 7 | cout << a << " " << (x + y + z - a - b) << " " << b; 8 | } -------------------------------------------------------------------------------- /Baekjoon/2753.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | ios::sync_with_stdio(0); cin.tie(0); 5 | int N; cin >> N; 6 | if (N % 400 == 0) { cout << 1; } 7 | else if (N % 4 == 0 && N % 100 != 0) { cout << 1; } 8 | else { cout << 0; } 9 | } -------------------------------------------------------------------------------- /Baekjoon/2810.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; string s; cin >> s; 7 | int probe = 0, result = 1; 8 | while (probe < N) { 9 | if (s[probe] == 'S') { probe++; } 10 | else { probe += 2; } 11 | result++; 12 | } 13 | cout << min(N, result); 14 | } -------------------------------------------------------------------------------- /Baekjoon/2839.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; int sum = 10000, x, y; 7 | // O(1) solution exists but lazy me! 8 | if (N == 4 || N == 7) { sum = -1; } 9 | for (int i = 0; i <= N; i += 5) { 10 | if ((N - i) % 3 == 0) { 11 | x = i / 5; y = (N - i) / 3; 12 | if ((x + y) < sum) { sum = x + y; } 13 | } 14 | } 15 | cout << sum; 16 | } -------------------------------------------------------------------------------- /Baekjoon/2851.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int acc[11] = {}, temp, idx = 1, Min = 1 << 30; 7 | for (int i = 1; i <= 10; i++) { 8 | cin >> temp; acc[i] = acc[i - 1] + temp; 9 | int delta = abs(acc[i] - 100); 10 | if (delta <= Min) { 11 | Min = delta; idx = i; 12 | } 13 | } 14 | cout << acc[idx]; 15 | } -------------------------------------------------------------------------------- /Baekjoon/2858.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int R, B, L, W; 7 | cin >> R >> B; 8 | for (int i = 1; i <= (R + 4) / 2; i++) { 9 | L = i; 10 | W = (R + 4) / 2 - L; 11 | if ((L - 2) * (W - 2) == B) { 12 | int Max = max(L, W); 13 | cout << Max << ' ' << L + W - Max; 14 | return 0; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Baekjoon/2869.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int A, B, V; cin >> A >> B >> V; 7 | int amount = A - B; 8 | cout << ((V - A) / amount) + ((V - A) % amount != 0) + 1; 9 | } -------------------------------------------------------------------------------- /Baekjoon/2884.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int H, M; cin >> H >> M; 7 | if (M >= 45) { cout << H << ' '; } 8 | else { cout << (H == 0 && M < 45 ? 23 : H - 1) << ' '; } 9 | cout << (M + 15) % 60; 10 | } -------------------------------------------------------------------------------- /Baekjoon/2902.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) { 5 | char input[101] = {}; 6 | scanf("%s", input); 7 | printf("%c", input[0]); 8 | for (int i = 1; i < strlen(input); i++) { 9 | if (input[i] == '-') { printf("%c", input[i + 1]); } 10 | } 11 | } -------------------------------------------------------------------------------- /Baekjoon/2903.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; cin >> N; 7 | cout << ((1 << N) + 1) * ((1 << N) + 1); 8 | } -------------------------------------------------------------------------------- /Baekjoon/2908.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | inline int form(int A) { 5 | int d1 = A % 10; 6 | int d2 = (A % 100 - d1) / 10; 7 | int d3 = (A / 100); 8 | return 100 * d1 + 10 * d2 + d3; 9 | } 10 | 11 | int main(void) { 12 | ios::sync_with_stdio(0); cin.tie(0); 13 | int A, B; cin >> A >> B; 14 | A = form(A); B = form(B); 15 | if (A > B) { cout << A; } else { cout << B; } 16 | } -------------------------------------------------------------------------------- /Baekjoon/2920.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | int input[8] = {}; int asc = 0, des = 0; 5 | for (int i = 0; i < 8; i++) { 6 | scanf("%d", &input[i]); 7 | if (i == 0 && input[0] == 1) { asc = 1; } 8 | if (i != 0 && asc) { if (input[i - 1] > input[i]) { asc = 0; } } 9 | if (i == 0 && input[0] == 8) { des = 1; } 10 | if (i != 0 && des) { if (input[i - 1] < input[i]) { des = 0; } } 11 | } 12 | if (asc) { printf("ascending"); } 13 | else if (des) { printf("descending"); } 14 | else { printf("mixed"); } 15 | } -------------------------------------------------------------------------------- /Baekjoon/2942.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int R, G; cin >> R >> G; 7 | int gcd = __gcd(R, G); 8 | for (int i = 1; i * i <= gcd; i++) { 9 | if (!(gcd % i)) { 10 | cout << i << ' ' << R / i << ' ' << G / i << '\n'; 11 | if (i * i != gcd) { 12 | cout << gcd / i << ' ' << (R / gcd) * i << ' ' << (G / gcd) * i << '\n'; 13 | } 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Baekjoon/2986.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int N, div = 0; cin >> N; 7 | for (int i = 2; i <= (int)sqrt(N); i++) { 8 | if (N % i == 0) { 9 | div = i; 10 | break; 11 | } 12 | } 13 | if (div) { 14 | cout << N - N / div; 15 | } else { 16 | cout << N - 1; 17 | } 18 | } -------------------------------------------------------------------------------- /Baekjoon/2997.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int x[3] = {}; cin >> x[0] >> x[1] >> x[2]; 7 | sort(x, x + 3); 8 | int d1 = x[1] - x[0], d2 = x[2] - x[1]; 9 | if (d1 == d2) { cout << x[2] + d1; } 10 | else { 11 | cout << (d1 < d2 ? x[1] + d1 : x[0] + d2); 12 | } 13 | } -------------------------------------------------------------------------------- /Baekjoon/3003.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int x, arr[6] = {1, 1, 2, 2, 2, 8}; 7 | for (int i = 0; i < 6; i++) { 8 | cin >> x; cout << arr[i] - x << ' '; 9 | } 10 | } -------------------------------------------------------------------------------- /Baekjoon/3009.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | inline int task(int x[]) { 5 | if (x[0] == x[1]) 6 | return x[2]; 7 | else if (x[1] == x[2]) 8 | return x[0]; 9 | else 10 | return x[1]; 11 | } 12 | 13 | int main(void) { 14 | ios::sync_with_stdio(false); cin.tie(nullptr); 15 | int x[3] = {}, y[3] = {}; 16 | for (int i = 0; i < 3; i++) 17 | cin >> x[i] >> y[i]; 18 | cout << task(x) << ' ' << task(y); 19 | } -------------------------------------------------------------------------------- /Baekjoon/3036.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int T, temp, gcd; cin >> T; int first; cin >> first; 7 | for (int i = 1; i < T; i++) { 8 | cin >> temp; gcd = __gcd(temp, first); 9 | cout << first / gcd << "/" << temp / gcd << '\n'; 10 | } 11 | } -------------------------------------------------------------------------------- /Baekjoon/3046.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int R1, S; cin >> R1 >> S; 7 | cout << 2 * S - R1; 8 | } -------------------------------------------------------------------------------- /Baekjoon/3047.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int D[3]; string s; 7 | cin >> D[0] >> D[1] >> D[2] >> s; 8 | sort(D, D + 3); 9 | cout << D[s[0] - 'A'] << ' ' << D[s[1] - 'A'] << ' ' << D[s[2] - 'A']; 10 | } -------------------------------------------------------------------------------- /Baekjoon/3049.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; 7 | cout << N * (N - 1) * (N - 2) * (N - 3) / 24; 8 | } -------------------------------------------------------------------------------- /Baekjoon/3052.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); int temp; 6 | bool output[42] = {}; int result = 0; 7 | for (int i = 0; i < 10; i++) { 8 | cin >> temp; output[temp % 42] = true; 9 | } 10 | for (int i = 0; i < 42; i++) { 11 | result += output[i]; 12 | } 13 | cout << result; 14 | } -------------------------------------------------------------------------------- /Baekjoon/3053.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | long double R; cin >> R; 7 | long double euclidean = R * R * M_PI; 8 | long double taxi = R * R * 2; 9 | cout << setprecision(15) << euclidean << '\n' << taxi; 10 | } -------------------------------------------------------------------------------- /Baekjoon/3474.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | inline void task() { 5 | int N; cin >> N; 6 | int cnt = 0; 7 | for (int i = 5; i <= N; i *= 5) { 8 | cnt += N / i; 9 | } 10 | cout << cnt << '\n'; 11 | } 12 | 13 | int main(void) { 14 | ios::sync_with_stdio(false); cin.tie(NULL); 15 | int T; cin >> T; 16 | while (T--) { task(); } 17 | } -------------------------------------------------------------------------------- /Baekjoon/4101.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int a, b; 7 | while (true) { 8 | cin >> a >> b; if (a == 0 && b == 0) { return 0; } 9 | cout << (a > b ? "Yes\n" : "No\n"); 10 | } 11 | } -------------------------------------------------------------------------------- /Baekjoon/4153.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int max(int a, int b) { return a < b ? b : a; } 4 | int min(int a, int b) { return a > b ? b : a; } 5 | 6 | int main(void) { 7 | int a, b, c, M, m, t; 8 | while (1) { 9 | scanf("%d %d %d", &a, &b, &c); if (a == 0 && b == 0 && c == 0) { return 0; } 10 | M = max(max(a, b), c); m = min(min(a, b), c); t = a + b + c - M - m; 11 | if (m * m + t * t == M * M) { printf("right\n"); } else { printf("wrong\n"); } 12 | } 13 | } -------------------------------------------------------------------------------- /Baekjoon/4504.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | int N; scanf("%d", &N); 4 | int num = 0; 5 | while (1) { 6 | scanf("%d", &num); if (num == 0) { return 0; } 7 | printf("%d is ", num); 8 | if (num % N != 0) { printf("NOT "); } 9 | printf("a multiple of %d.\n", N); 10 | } 11 | } -------------------------------------------------------------------------------- /Baekjoon/4592.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int N, temp, prev = -1; 7 | while (true) { 8 | cin >> N; if (!N) { return 0; } 9 | for (int i = 0; i < N; i++) { 10 | cin >> temp; 11 | if (temp != prev) { cout << temp << ' '; } 12 | prev = temp; 13 | } 14 | cout << "$\n"; 15 | prev = -1; 16 | } 17 | } -------------------------------------------------------------------------------- /Baekjoon/4766.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int start = true; double temp, input; 7 | while (true) { 8 | cin >> input; 9 | if (input == 999) { return 0; } 10 | if (start) { start = false; temp = input; } 11 | else { 12 | cout << fixed << setprecision(2) << input - temp << '\n'; 13 | temp = input; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Baekjoon/4999.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | string s1, s2; cin >> s1 >> s2; 7 | cout << (s1.length() >= s2.length() ? "go" : "no"); 8 | } -------------------------------------------------------------------------------- /Baekjoon/5026.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) { 6 | int N; scanf("%d", &N); 7 | for (int i = 0; i < N; i++) { 8 | char input[10] = {0, }; 9 | scanf("%s", input); 10 | if (input[1] == '=') { printf("skipped\n"); } 11 | else { 12 | int result = 0; 13 | char* token = strtok(input, "+"); 14 | while (token != NULL) { 15 | result += atoi(token); 16 | token = strtok(NULL, "+"); 17 | } 18 | printf("%d\n", result); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Baekjoon/5063.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, r, e, c; cin >> N; 7 | for (int i = 0; i < N; i++) { 8 | cin >> r >> e >> c; 9 | int temp = e - c; 10 | if (temp > r) { cout << "advertise\n"; } 11 | else if (temp < r) { cout << "do not advertise\n"; } 12 | else { cout << "does not matter\n"; } 13 | } 14 | } -------------------------------------------------------------------------------- /Baekjoon/5086.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N, M; 7 | while (true) { 8 | cin >> N >> M; 9 | if (M == 0 && N == 0) { break; } 10 | if (M % N == 0) { cout << "factor\n"; } 11 | else if (N % M == 0) { cout << "multiple\n"; } 12 | else { cout << "neither\n"; } 13 | } 14 | } -------------------------------------------------------------------------------- /Baekjoon/5101.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int a, b, c; 7 | while (true) { 8 | cin >> a >> b >> c; if (a == 0 && b == 0 && c == 0) { return 0; } 9 | if ((c - a) % b == 0) { 10 | int output = (c - a) / b + 1; 11 | if (output >= 1) { cout << output << '\n'; } else { cout << "X\n"; } 12 | } else { cout << "X\n"; } 13 | } 14 | } -------------------------------------------------------------------------------- /Baekjoon/5217.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int T, a; cin >> T; 7 | while (T--) { 8 | cin >> a; 9 | cout << "Pairs for " << a << ':'; 10 | for (int i = 1; i <= a >> 1; i++) { 11 | if (i << 1 != a) { 12 | cout << ' ' << i << ' ' << a - i; 13 | } 14 | if (i != a >> 1 && (i + 1) << 1 != a) { cout << ','; } 15 | } 16 | cout << '\n'; 17 | } 18 | } -------------------------------------------------------------------------------- /Baekjoon/5337.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | printf(". . .\n| | _ | _. _ ._ _ _\n|/\\|(/.|(_.(_)[ | )(/."); 4 | } -------------------------------------------------------------------------------- /Baekjoon/5347.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int N; 7 | long long a, b; 8 | cin >> N; 9 | while (N--) { 10 | cin >> a >> b; 11 | cout << a * b / __gcd(a, b) << '\n'; 12 | } 13 | } -------------------------------------------------------------------------------- /Baekjoon/5543.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int B[3], D[2]; int Min = 1 << 30; 7 | for (int i = 0; i < 3; i++) { cin >> B[i]; } 8 | for (int i = 0; i < 2; i++) { cin >> D[i]; } 9 | for (int i = 0; i < 3; i++) { 10 | for (int j = 0; j < 2; j++) { 11 | Min = min(Min, B[i] + D[j]); 12 | } 13 | } 14 | cout << Min - 50; 15 | } -------------------------------------------------------------------------------- /Baekjoon/5554.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int acc = 0, minute, hour, temp; 7 | for (int i = 0; i < 4; i++) { 8 | cin >> temp; acc += temp; 9 | } 10 | hour = acc / 60; 11 | minute = acc % 60; 12 | cout << hour << '\n' << minute; 13 | } -------------------------------------------------------------------------------- /Baekjoon/5565.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int sum, temp; cin >> sum; 7 | for (int i = 0; i < 9; i++) { cin >> temp; sum -= temp; } 8 | cout << sum; 9 | } -------------------------------------------------------------------------------- /Baekjoon/5585.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; cin >> N; N = 1000 - N; 7 | int result = 0; int A[6] = {500, 100, 50, 10, 5, 1}; 8 | int cnt = 0; 9 | while (N != 0) { 10 | if (N >= A[cnt]) { 11 | result += N / A[cnt]; 12 | N %= A[cnt]; 13 | } 14 | cnt++; 15 | } 16 | cout << result; 17 | } -------------------------------------------------------------------------------- /Baekjoon/5597.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | bool D[30] = {}; int temp; 7 | for (int i = 0; i < 28; i++) { 8 | cin >> temp; D[temp - 1] = true; 9 | } 10 | for (int i = 0; i < 30; i++) { 11 | if (!D[i]) { cout << i + 1 << '\n'; } 12 | } 13 | } -------------------------------------------------------------------------------- /Baekjoon/5598.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(void) { 4 | char input[1001] = {}; scanf("%s", input); 5 | for (int i = 0; i < strlen(input); i++) { 6 | input[i] = (26 + input[i] - 'A' - 3) % 26 + 'A'; 7 | } 8 | printf("%s", input); 9 | } -------------------------------------------------------------------------------- /Baekjoon/5988.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; cin >> N; string s; 7 | while (N--) { 8 | cin >> s; cout << ((s[s.length() - 1] - '0') % 2 ? "odd\n" : "even\n"); 9 | } 10 | } -------------------------------------------------------------------------------- /Baekjoon/6321.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int N; cin >> N; 7 | string s; 8 | for (int i = 1; i <= N; i++) { 9 | cin >> s; 10 | cout << "String #" << i << '\n'; 11 | for (int j = 0; j < s.length(); j++) 12 | s[j] = (s[j] - 'A' + 1) % 26 + 'A'; 13 | cout << s << '\n'; 14 | if (i != N) 15 | cout << '\n'; 16 | } 17 | } -------------------------------------------------------------------------------- /Baekjoon/6359.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int T, N; cin >> T; 7 | for (int t = 0; t < T; t++) { 8 | cin >> N; cout << (int) sqrt(N) << '\n'; 9 | } 10 | } -------------------------------------------------------------------------------- /Baekjoon/6591.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int N, K; 7 | while (true) { 8 | cin >> N >> K; 9 | if (N == 0 && K == 0) 10 | return 0; 11 | K = min(K, N - K); 12 | long long result = 1; 13 | for (int i = 1; i <= K; i++) 14 | result = result * (N - i + 1) / i; 15 | cout << result << '\n'; 16 | } 17 | } -------------------------------------------------------------------------------- /Baekjoon/7489.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int D[1002] = {}, temp; 7 | D[1] = 1; 8 | for (int i = 2; i <= 1001; i++) { 9 | temp = i; 10 | D[i] = D[i - 1]; 11 | while (temp % 5 == 0) { 12 | temp /= 5; 13 | D[i] /= 2; 14 | } 15 | D[i] *= temp; 16 | D[i] %= 10000; 17 | } 18 | int T, N; 19 | cin >> T; 20 | while (T--) { 21 | cin >> N; 22 | cout << D[N] % 10 << '\n'; 23 | } 24 | } -------------------------------------------------------------------------------- /Baekjoon/7567.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | string s; cin >> s; char prev; int result = 10; 7 | for (int i = 0; i < s.length(); i++) { 8 | if (i > 0) { 9 | if (prev == s[i]) { result += 5; } 10 | else { result += 10;} 11 | } 12 | prev = s[i]; 13 | } 14 | cout << result; 15 | } -------------------------------------------------------------------------------- /Baekjoon/7785.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); int N; 6 | set> S; priority_queue PQ; string name, status; 7 | cin >> N; 8 | for (int i = 0; i < N; i++) { // O(N * log(N)) 9 | cin >> name >> status; 10 | if (!status.compare("enter")) { S.insert(name); } 11 | else { auto it = S.find(name); S.erase(it); } 12 | } 13 | for (auto it = S.begin(); it != S.end(); it++) { 14 | cout << *it << '\n'; // set is already sorted :D 15 | } 16 | } -------------------------------------------------------------------------------- /Baekjoon/8393.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int N; cin >> N; cout << N * (N + 1) / 2; 7 | } -------------------------------------------------------------------------------- /Baekjoon/8741.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(NULL); 6 | int K; cin >> K; 7 | cout << string(K, '1') << string(K - 1, '0'); 8 | } -------------------------------------------------------------------------------- /Baekjoon/8958.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) { 5 | int T, ans, idx; scanf("%d", &T); char input[81] = {}; 6 | for (int i = 0; i < T; i++) { 7 | scanf("%s", input); ans = 0; idx = 0; 8 | for (int j = 0; j < strlen(input); j++) { 9 | if (input[j] == 'O') { idx++; } 10 | else { ans += idx * (idx + 1) / 2; idx = 0; } 11 | } 12 | ans += idx * (idx + 1) / 2; 13 | printf("%d\n", ans); 14 | } 15 | } -------------------------------------------------------------------------------- /Baekjoon/9012.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | string s; getline(cin, s); int N = stoi(s); 7 | int cnt = 0; 8 | for (int i = 0; i < N; i++) { 9 | getline(cin, s); 10 | for (auto it = s.begin(); it != s.end(); it++) { 11 | if ((*it) == '(') { cnt++; } 12 | else { cnt--; } 13 | if (cnt < 0) { break; } 14 | } 15 | if (cnt != 0) { printf("NO\n"); } 16 | else { printf("YES\n"); } 17 | cnt = 0; 18 | } 19 | } -------------------------------------------------------------------------------- /Baekjoon/9085.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int T, num, temp, result; cin >> T; 7 | for (int i = 0; i < T; i++) { 8 | cin >> num; result = 0; 9 | for (int j = 0; j < num; j++) { cin >> temp; result += temp; } 10 | cout << result << '\n'; 11 | } 12 | } -------------------------------------------------------------------------------- /Baekjoon/9086.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; string s; cin >> N; getline(cin, s); 7 | for (int i = 0; i < N; i++) { 8 | getline(cin, s); cout << s[0] << s[s.length() - 1] << '\n'; 9 | } 10 | } -------------------------------------------------------------------------------- /Baekjoon/9095.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | int n; cin >> n; int target[n]; 6 | for (int i = 0; i < n; i++) { cin >> target[i]; } 7 | int k = *max_element(target, target + n); 8 | int D[k + 1] = {}; 9 | D[1] = 1; D[2] = 2; D[3] = 4; 10 | for (int i = 4; i <= k; i++) { 11 | D[i] = D[i - 1] + D[i - 2] + D[i - 3]; 12 | } 13 | for (int i = 0; i < n; i++) { 14 | cout << D[target[i]] << '\n'; 15 | } 16 | } -------------------------------------------------------------------------------- /Baekjoon/9316.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; cin >> N; 7 | for (int i = 1; i <= N; i++) { 8 | cout << "Hello World, Judge " << i << "!\n"; 9 | } 10 | } -------------------------------------------------------------------------------- /Baekjoon/9325.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int T; cin >> T; 7 | for (int i = 0; i < T; i++) { 8 | int start, cnt, num, amount, temp; cin >> start; 9 | temp = start; cin >> cnt; 10 | for (int j = 0; j < cnt; j++) { 11 | cin >> num >> amount; temp += num * amount; 12 | } 13 | cout << temp << '\n'; 14 | } 15 | } -------------------------------------------------------------------------------- /Baekjoon/9461.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int T, max = 0; cin >> T; int input[T] = {}; 7 | for (int i = 0; i < T; i++) { 8 | cin >> input[i]; if (max < input[i]) { max = input[i]; } 9 | } 10 | long long D[max] = {}; D[0] = D[1] = D[2] = 1; D[3] = D[4] = 2; 11 | for (int i = 5; i < max; i++) { 12 | D[i] = D[i - 1] + D[i - 5]; 13 | } 14 | for (int i = 0; i < T; i++) { 15 | cout << D[input[i] - 1] << '\n'; 16 | } 17 | } -------------------------------------------------------------------------------- /Baekjoon/9498.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | int N; scanf("%d", &N); 3 | if (N >= 90) { printf("A"); } 4 | else if (N >= 80) { printf("B"); } 5 | else if (N >= 70) { printf("C"); } 6 | else if (N >= 60) { printf("D"); } 7 | else { printf("F"); } 8 | } -------------------------------------------------------------------------------- /Baekjoon/9507.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | long long D[68] = {}; D[0] = D[1] = 1; D[2] = 2; D[3] = 4; 7 | for (int i = 4; i < 68; i++) { 8 | D[i] = D[i - 1] + D[i - 2] + D[i - 3] + D[i - 4]; 9 | } 10 | int T, idx; cin >> T; 11 | while (T--) { 12 | cin >> idx; 13 | cout << D[idx] << '\n'; 14 | } 15 | } -------------------------------------------------------------------------------- /Baekjoon/9613.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(0); cin.tie(0); 6 | int T, cnt; long long sum; cin >> T; 7 | for (int t = 0; t < T; t++) { 8 | cin >> cnt; int input[cnt] = {}; sum = 0; 9 | for (int i = 0; i < cnt; i++) { cin >> input[i]; } 10 | for (int i = 0; i < cnt; i++) { 11 | for (int j = i + 1; j < cnt; j++) { 12 | sum += __gcd(input[i], input[j]); 13 | } 14 | } 15 | cout << sum << '\n'; 16 | } 17 | } -------------------------------------------------------------------------------- /Baekjoon/cpptest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) 5 | { 6 | ios::sync_with_stdio(0); // only use cout 7 | cin.tie(0); // stop flushing 8 | 9 | } -------------------------------------------------------------------------------- /Baekjoon/playground.c: -------------------------------------------------------------------------------- 1 | main(){printf("Hello World!\n");} -------------------------------------------------------------------------------- /Baekjoon/playground.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int func1(int a, int b, int m) 5 | { 6 | int val = 1; 7 | while(b--) val *= a; 8 | return val; 9 | } 10 | 11 | int main(void) 12 | { 13 | cout << func1(6, 12, 5); 14 | } -------------------------------------------------------------------------------- /CodeJam/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pcw109550/problem-solving/333d850a5261b49f32350b6a723c731156b24b8a/CodeJam/.gitkeep -------------------------------------------------------------------------------- /LeetCode/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pcw109550/problem-solving/333d850a5261b49f32350b6a723c731156b24b8a/LeetCode/.gitkeep -------------------------------------------------------------------------------- /LeetCode/actors-and-directors-who-cooperated-at-least-three-times.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT actor_id, director_id 3 | FROM ActorDirector 4 | GROUP BY actor_id, director_id 5 | HAVING COUNT(timestamp) >= 3; 6 | -------------------------------------------------------------------------------- /LeetCode/add-digits.cpp: -------------------------------------------------------------------------------- 1 | // 258. Add Digits 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int addDigits(int num) { 8 | // O(1) 9 | int result; 10 | while (num >= 10) { 11 | int next = 0; 12 | while (num > 0) { 13 | next += num % 10; 14 | num /= 10; 15 | } 16 | num = next; 17 | } 18 | result = num; 19 | return result; 20 | } 21 | }; 22 | 23 | int main(void) { 24 | Solution s; 25 | } -------------------------------------------------------------------------------- /LeetCode/add-minimum-number-of-rungs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int addRungs(vector& rungs, int dist) { 8 | // O(N) 9 | int N = rungs.size(); 10 | int result = 0; 11 | for (int i = 0; i < N; i++) { 12 | int delta = rungs[i] - (i >= 1 ? rungs[i - 1] : 0); 13 | result += (delta - 1) / dist; 14 | } 15 | return result; 16 | } 17 | }; -------------------------------------------------------------------------------- /LeetCode/adding-spaces-to-a-string.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Solution { 7 | public: 8 | string addSpaces(string s, vector& spaces) { 9 | // O(M + N) 10 | string result; 11 | int N = s.size(); 12 | int pos = 0; 13 | for (int i = 0; i < N; i++) { 14 | if (pos < spaces.size() && spaces[pos] == i) { 15 | result.push_back(' '); 16 | pos++; 17 | } 18 | result.push_back(s[i]); 19 | } 20 | return result; 21 | } 22 | }; -------------------------------------------------------------------------------- /LeetCode/arranging-coins.cpp: -------------------------------------------------------------------------------- 1 | // 441. Arranging Coins 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int arrangeCoins(int n) { 8 | // O(sqrt(N)) 9 | int result = 0; 10 | long long c = 0; 11 | for (long long i = 1; i <= 1000000; i++) { 12 | c += i; 13 | if (n < c) { 14 | result = i - 1; 15 | break; 16 | } 17 | } 18 | return result; 19 | } 20 | }; 21 | 22 | int main(void) { 23 | Solution s; 24 | } -------------------------------------------------------------------------------- /LeetCode/array-partition-i.cpp: -------------------------------------------------------------------------------- 1 | // 561. Array Partition I 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | class Solution { 8 | public: 9 | int arrayPairSum(vector& nums) { 10 | // O(N * log(N)) 11 | int N = nums.size(); 12 | int result = 0; 13 | sort(nums.begin(), nums.end()); 14 | for (int i = 0; i < N; i += 2) 15 | result += nums[i]; 16 | return result; 17 | } 18 | }; 19 | 20 | int main(void) { 21 | Solution s; 22 | } -------------------------------------------------------------------------------- /LeetCode/article-views-i.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT DISTINCT author_id as 'id' 3 | FROM Views 4 | WHERE author_id = viewer_id 5 | ORDER BY author_id ASC; -------------------------------------------------------------------------------- /LeetCode/bank-account-summary-ii.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | 3 | SELECT U.name, T.balance 4 | FROM 5 | ( 6 | SELECT account, SUM(amount) as 'balance' 7 | FROM Transactions 8 | GROUP BY account 9 | HAVING SUM(amount) > 10000 10 | ) AS T 11 | INNER JOIN Users as U 12 | ON T.account = U.account -------------------------------------------------------------------------------- /LeetCode/best-time-to-buy-and-sell-stock-ii.cpp: -------------------------------------------------------------------------------- 1 | // 122. Best Time to Buy and Sell Stock II 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | class Solution { 8 | public: 9 | int maxProfit(vector& prices) { 10 | // O(N) 11 | int result = 0; 12 | for (int i = 0; i < prices.size() - 1; i++) 13 | if (prices[i] < prices[i + 1]) 14 | result += prices[i + 1] - prices[i]; 15 | return result; 16 | } 17 | }; 18 | 19 | int main(void) { 20 | Solution s; 21 | } -------------------------------------------------------------------------------- /LeetCode/big-countries.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT name, population, area from World WHERE 3 | area >= 3000000 OR 4 | population >= 25000000; -------------------------------------------------------------------------------- /LeetCode/binary-number-with-alternating-bits.cpp: -------------------------------------------------------------------------------- 1 | // 693. Binary Number with Alternating Bits 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | bool hasAlternatingBits(int n) { 8 | // O(log(N)) 9 | bool prev = n & 1; 10 | n >>= 1; 11 | while (n > 0) { 12 | if ((n & 1) == prev) 13 | return false; 14 | n >>= 1; 15 | prev = !prev; 16 | } 17 | return true; 18 | } 19 | }; 20 | 21 | int main(void) { 22 | Solution s; 23 | } -------------------------------------------------------------------------------- /LeetCode/broken-calculator.cpp: -------------------------------------------------------------------------------- 1 | // 991. Broken Calculator 2 | #include 3 | 4 | class Solution { 5 | public: 6 | int brokenCalc(int X, int Y) { 7 | // O(log(N)) 8 | int result = 0; 9 | while (Y > X) { 10 | result++; 11 | if (Y % 2 == 1) 12 | Y++; 13 | else 14 | Y /= 2; 15 | } 16 | result += X - Y; 17 | return result; 18 | } 19 | }; 20 | 21 | int main(void) { 22 | Solution s; 23 | } -------------------------------------------------------------------------------- /LeetCode/calculate-money-in-leetcode-bank.cpp: -------------------------------------------------------------------------------- 1 | // 1716. Calculate Money in Leetcode Bank 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int totalMoney(int n) { 8 | // O(1) 9 | int r = n % 7; 10 | int q = n / 7; 11 | int result = 0; 12 | result += 7 * q * (q - 1) / 2; 13 | result += 7 * 8 / 2 * q; 14 | result += r * q + r * (r + 1) / 2; 15 | return result; 16 | } 17 | }; 18 | 19 | int main(void) { 20 | Solution s; 21 | } -------------------------------------------------------------------------------- /LeetCode/calculate-special-bonus.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT 3 | employee_id, 4 | IF ( 5 | employee_id % 2 = 1 6 | AND name NOT LIKE "M%", 7 | salary, 8 | 0 9 | ) as 'bonus' 10 | FROM Employees 11 | ORDER BY employee_id; -------------------------------------------------------------------------------- /LeetCode/capital-gainloss.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT 3 | stock_name, 4 | SUM(IF(operation = 'Sell', price, -price)) as 'capital_gain_loss' 5 | FROM Stocks 6 | GROUP BY stock_name; -------------------------------------------------------------------------------- /LeetCode/climbing-stairs.cpp: -------------------------------------------------------------------------------- 1 | // 70. Climbing Stairs 2 | #include 3 | 4 | class Solution { 5 | public: 6 | int climbStairs(int n) { 7 | // O(n) 8 | int D[46] = {}; 9 | D[1] = 1; 10 | D[2] = 2; 11 | for (int i = 3; i <= n; i++) 12 | D[i] = D[i - 1] + D[i - 2]; 13 | return D[n]; 14 | } 15 | }; 16 | 17 | int main(void) { 18 | Solution s; 19 | for (int i = 1; i <= 45; i++) 20 | std::cout << s.climbStairs(i) << std::endl; 21 | } -------------------------------------------------------------------------------- /LeetCode/combine-two-tables.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT firstName, lastName, 3 | ( 4 | SELECT city FROM Address 5 | WHERE Address.personId = Person.personId 6 | ) as 'city', 7 | ( 8 | SELECT state FROM Address 9 | WHERE Address.personId = Person.personId 10 | ) as 'state' 11 | FROM Person; -------------------------------------------------------------------------------- /LeetCode/contains-duplicate.cpp: -------------------------------------------------------------------------------- 1 | // 217. Contains Duplicate 2 | #include 3 | #include 4 | #include 5 | 6 | class Solution { 7 | public: 8 | bool containsDuplicate(std::vector& nums) { 9 | // O(N) 10 | std::unordered_set S; 11 | for (auto num : nums) { 12 | if (S.count(num)) 13 | return true; 14 | S.insert(num); 15 | } 16 | return false; 17 | } 18 | }; 19 | 20 | int main(void) { 21 | Solution s; 22 | } -------------------------------------------------------------------------------- /LeetCode/count-all-valid-pickup-and-delivery-options.cpp: -------------------------------------------------------------------------------- 1 | // 1359. Count All Valid Pickup and Delivery Options 2 | #include 3 | #include 4 | using namespace std; 5 | #define FIELD 1000000007 6 | 7 | class Solution { 8 | public: 9 | int countOrders(int n) { 10 | // O(N) 11 | long long result = 1; 12 | // (2 * n)! / (2 ** n) 13 | for (int i = 2 * n; i >= 1; i--) 14 | result = (result * (i % 2 ? i : i / 2)) % FIELD; 15 | return result; 16 | } 17 | }; 18 | 19 | int main(void) { 20 | Solution s; 21 | } 22 | -------------------------------------------------------------------------------- /LeetCode/customer-placing-the-largest-number-of-orders.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT customer_number FROM ( 3 | SELECT customer_number, COUNT(order_number) AS 'cnt' 4 | FROM Orders 5 | GROUP BY customer_number 6 | ORDER BY cnt DESC 7 | LIMIT 1 8 | ) AS T 9 | -------------------------------------------------------------------------------- /LeetCode/customer-who-visited-but-did-not-make-any-transactions.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT 3 | customer_id, count(customer_id) as 'count_no_trans' 4 | FROM Visits 5 | LEFT JOIN Transactions ON Visits.visit_id = Transactions.visit_id 6 | WHERE Transactions.visit_id IS NULL 7 | GROUP BY customer_id; -------------------------------------------------------------------------------- /LeetCode/customers-who-never-order.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT name 3 | AS 'customers' 4 | FROM Customers 5 | WHERE id NOT IN ( 6 | SELECT DISTINCT customerId 7 | FROM Orders 8 | ); -------------------------------------------------------------------------------- /LeetCode/daily-leads-and-partners.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT 3 | date_id, 4 | make_name, 5 | COUNT(DISTINCT lead_id) AS 'unique_leads', 6 | COUNT(DISTINCT partner_id) AS 'unique_partners' 7 | FROM DailySales 8 | GROUP BY date_id, make_name; -------------------------------------------------------------------------------- /LeetCode/delete-duplicate-emails.mysql: -------------------------------------------------------------------------------- 1 | # Please write a DELETE statement and DO NOT write a SELECT statement. 2 | # Write your MySQL query statement below 3 | DELETE r1 4 | FROM Person r1, Person r2 5 | WHERE r1.id > r2.id 6 | AND r1.email = r2.email; 7 | -------------------------------------------------------------------------------- /LeetCode/determine-color-of-a-chessboard-square.cpp: -------------------------------------------------------------------------------- 1 | // 1812. Determine Color of a Chessboard Square 2 | #include 3 | #include 4 | 5 | class Solution { 6 | public: 7 | bool squareIsWhite(std::string coordinates) { 8 | // O(1) 9 | int a = coordinates[0] - 'a'; 10 | int b = coordinates[1] - '1'; 11 | return (a + b) % 2; 12 | } 13 | }; 14 | 15 | int main(void) { 16 | Solution s; 17 | } -------------------------------------------------------------------------------- /LeetCode/distribute-candies.cpp: -------------------------------------------------------------------------------- 1 | // 575. Distribute Candies 2 | #include 3 | #include 4 | #include 5 | 6 | class Solution { 7 | public: 8 | int distributeCandies(std::vector& candyType) { 9 | // O(N) 10 | std::unordered_set S; 11 | for (auto candy : candyType) 12 | S.insert(candy); 13 | return S.size() <= candyType.size() / 2 ? S.size() : candyType.size() / 2; 14 | } 15 | }; 16 | 17 | int main(void) { 18 | Solution s; 19 | } -------------------------------------------------------------------------------- /LeetCode/duplicate-emails.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT Email 3 | FROM ( 4 | SELECT Email, COUNT(id) as 'count' 5 | FROM Person 6 | GROUP BY Email 7 | ) AS T 8 | WHERE count > 1; 9 | -------------------------------------------------------------------------------- /LeetCode/employees-with-missing-information.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT employee_id FROM Employees 3 | WHERE employee_id NOT IN ( 4 | SELECT employee_id FROM Salaries 5 | ) 6 | UNION 7 | SELECT employee_id FROM Salaries 8 | WHERE employee_id NOT IN ( 9 | SELECT employee_id FROM Employees 10 | ) 11 | ORDER BY employee_id; -------------------------------------------------------------------------------- /LeetCode/excel-sheet-column-number.cpp: -------------------------------------------------------------------------------- 1 | // 171. Excel Sheet Column Number 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Solution { 7 | public: 8 | int titleToNumber(string columnTitle) { 9 | // O(N) 10 | int result = 0; 11 | int N = columnTitle.size(); 12 | for (auto c : columnTitle) { 13 | result *= 26; 14 | result += c - 'A' + 1; 15 | } 16 | return result; 17 | } 18 | }; 19 | 20 | int main(void) { 21 | Solution s; 22 | } 23 | -------------------------------------------------------------------------------- /LeetCode/factorial-trailing-zeroes.cpp: -------------------------------------------------------------------------------- 1 | // 172. Factorial Trailing Zeroes 2 | #include 3 | 4 | class Solution { 5 | public: 6 | int trailingZeroes(int n) { 7 | // O(log(N)) 8 | if (n <= 4) 9 | return 0; 10 | int result = 0; 11 | for (long long i = 5; i <= static_cast(n); i *= 5) { 12 | result += n / i; 13 | } 14 | return result; 15 | } 16 | }; 17 | 18 | int main(void) { 19 | Solution s; 20 | std::cout << s.trailingZeroes(120); 21 | } -------------------------------------------------------------------------------- /LeetCode/fibonacci-number.cpp: -------------------------------------------------------------------------------- 1 | // 509. Fibonacci Number 2 | #include 3 | 4 | class Solution { 5 | public: 6 | int fib(int N) { 7 | // O(N) 8 | int a = 0, b = 1, temp; 9 | while (N--) { 10 | temp = a + b; 11 | a = b; 12 | b = temp; 13 | } 14 | return a; 15 | } 16 | }; 17 | 18 | int main(void) { 19 | Solution s; 20 | int N = 30; 21 | std::cout << s.fib(N); 22 | } -------------------------------------------------------------------------------- /LeetCode/find-customer-referee.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT name 3 | FROM Customer 4 | WHERE referee_id != 2 5 | OR referee_id is NULL; -------------------------------------------------------------------------------- /LeetCode/find-followers-count.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT 3 | user_id, COUNT(follower_id) as 'followers_count' 4 | FROM Followers 5 | GROUP BY user_id 6 | ORDER BY user_id; -------------------------------------------------------------------------------- /LeetCode/find-n-unique-integers-sum-up-to-zero.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | vector sumZero(int n) { 8 | // O(N) 9 | vector result; 10 | for (int i = 1; i <= n / 2; i++) { 11 | result.push_back(i); 12 | result.push_back(-i); 13 | } 14 | if (n % 2) 15 | result.push_back(0); 16 | return result; 17 | } 18 | }; -------------------------------------------------------------------------------- /LeetCode/find-total-time-spent-by-each-employee.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT event_day as 'day', emp_id, SUM(out_time - in_time) AS 'total_time' 3 | FROM Employees 4 | GROUP BY event_day, emp_id; -------------------------------------------------------------------------------- /LeetCode/find-triangular-sum-of-an-array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int triangularSum(vector& nums) { 8 | // O(N ** 2) 9 | int N = nums.size(); 10 | vector curr = nums, next; 11 | for (int i = 0; i < N - 1; i++) { 12 | next.clear(); 13 | for (int j = 0; j < curr.size() - 1; j++) 14 | next.push_back((curr[j] + curr[j + 1]) % 10); 15 | curr = next; 16 | } 17 | int result = curr[0]; 18 | return result; 19 | } 20 | }; -------------------------------------------------------------------------------- /LeetCode/fix-names-in-a-table.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT user_id, CONCAT(UPPER(SUBSTR(name, 1, 1)), LOWER(SUBSTR(name, 2))) as 'name' 3 | FROM Users 4 | ORDER BY user_id; -------------------------------------------------------------------------------- /LeetCode/game-play-analysis-i.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT player_id, MIN(event_date) AS 'first_login' 3 | FROM Activity 4 | GROUP BY player_id; -------------------------------------------------------------------------------- /LeetCode/global-and-local-inversions.cpp: -------------------------------------------------------------------------------- 1 | // 775. Global and Local Inversions 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | class Solution { 8 | public: 9 | bool isIdealPermutation(std::vector& A) { 10 | // O(N) 11 | int N = A.size(); 12 | for (int i = 0; i < N; i++) 13 | if (i - A[i] > 1 || i - A[i] < -1) 14 | return false; 15 | return true; 16 | } 17 | }; 18 | 19 | int main(void) { 20 | Solution s; 21 | } -------------------------------------------------------------------------------- /LeetCode/group-sold-products-by-the-date.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT sell_date, COUNT(DISTINCT product) as 'num_sold', GROUP_CONCAT(DISTINCT product ORDER BY product) as 'products' 3 | FROM Activities 4 | GROUP BY sell_date; -------------------------------------------------------------------------------- /LeetCode/hamming-distance.cpp: -------------------------------------------------------------------------------- 1 | // 461. Hamming Distance 2 | #include 3 | 4 | class Solution { 5 | public: 6 | int hammingDistance(int x, int y) { 7 | return __builtin_popcount(x ^ y); 8 | } 9 | }; 10 | 11 | int main(void) { 12 | Solution s; 13 | int result = s.hammingDistance(1, 4); 14 | std::cout << result; 15 | } -------------------------------------------------------------------------------- /LeetCode/house-robber.cpp: -------------------------------------------------------------------------------- 1 | // 198. House Robber 2 | #include 3 | #include 4 | #include 5 | 6 | class Solution { 7 | public: 8 | int rob(std::vector& nums) { 9 | // O(N) 10 | int N = nums.size(); 11 | int D[101][2] = {}; 12 | for (int i = 0; i < N; i++) { 13 | D[i + 1][0] = D[i][1] + nums[i]; 14 | D[i + 1][1] = std::max(D[i][0], D[i][1]); 15 | } 16 | return std::max(D[N][0], D[N][1]); 17 | } 18 | }; 19 | 20 | int main(void) { 21 | Solution s; 22 | } -------------------------------------------------------------------------------- /LeetCode/is-subsequence.cpp: -------------------------------------------------------------------------------- 1 | // 392. Is Subsequence 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Solution { 7 | public: 8 | bool isSubsequence(string s, string t) { 9 | // O(N) 10 | int N = t.size(); 11 | int probe = 0; 12 | for (int i = 0; i < N; i++) { 13 | if (s[probe] == t[i]) 14 | probe++; 15 | } 16 | return probe == s.size(); 17 | } 18 | }; 19 | 20 | int main(void) { 21 | Solution s; 22 | } 23 | -------------------------------------------------------------------------------- /LeetCode/jump-game.cpp: -------------------------------------------------------------------------------- 1 | // 55. Jump Game 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | class Solution { 8 | public: 9 | bool canJump(vector& nums) { 10 | // O(N) 11 | int N = nums.size(); 12 | int p = 0; 13 | for (int i = 0; i < N; i++) { 14 | if (i <= p) 15 | p = max(p, i + nums[i]); 16 | else 17 | return false; 18 | } 19 | return true; 20 | } 21 | }; 22 | 23 | int main(void) { 24 | Solution s; 25 | } -------------------------------------------------------------------------------- /LeetCode/length-of-last-word.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int lengthOfLastWord(string s) { 8 | // O(N) 9 | int N = s.size(); 10 | int result = 0; 11 | int probe = N - 1; 12 | while (s[probe] == ' ') 13 | probe--; 14 | for (int i = probe; i >= 0; i--) 15 | if (s[i] == ' ') 16 | break; 17 | else 18 | result++; 19 | return result; 20 | } 21 | }; -------------------------------------------------------------------------------- /LeetCode/market-analysis-i.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT user_id AS 'buyer_id', join_date, COUNT(order_id) as 'orders_in_2019' 3 | FROM Users as T 4 | LEFT JOIN Orders as U 5 | ON U.buyer_id = T.user_id 6 | AND YEAR(U.order_date) = '2019' 7 | GROUP BY user_id; -------------------------------------------------------------------------------- /LeetCode/matrix-diagonal-sum.cpp: -------------------------------------------------------------------------------- 1 | // 1572. Matrix Diagonal Sum 2 | #include 3 | #include 4 | 5 | class Solution { 6 | public: 7 | int diagonalSum(std::vector >& mat) { 8 | // O(N) 9 | int sum = 0; 10 | int N = mat.size(); 11 | for (int i = 0; i < N; i++) { 12 | sum += mat[i][i] + mat[i][N - i - 1]; 13 | } 14 | if (N % 2) 15 | sum -= mat[N / 2][N / 2]; 16 | return sum; 17 | } 18 | }; 19 | 20 | int main(void) { 21 | Solution s; 22 | } -------------------------------------------------------------------------------- /LeetCode/maximum-69-number.cpp: -------------------------------------------------------------------------------- 1 | // 1323. Maximum 69 Number 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int maximum69Number (int num) { 8 | // O(log(N)) 9 | int temp = num; 10 | int target = 0; 11 | int cur = 1; 12 | while (temp > 0) { 13 | if (temp % 10 == 6) 14 | target = cur; 15 | cur *= 10; 16 | temp /= 10; 17 | } 18 | num += target * 3; 19 | return num; 20 | } 21 | }; 22 | 23 | int main(void) { 24 | Solution s; 25 | } 26 | -------------------------------------------------------------------------------- /LeetCode/maximum-number-of-coins-you-can-get.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Solution { 7 | public: 8 | int maxCoins(vector& piles) { 9 | // O(N * log(N)) 10 | int N = piles.size() / 3; 11 | int result = 0; 12 | sort(piles.begin(), piles.end()); 13 | for (int i = 0; i < N; i++) 14 | result += piles[N + 2 * i]; 15 | return result; 16 | } 17 | }; -------------------------------------------------------------------------------- /LeetCode/maximum-product-of-two-elements-in-an-array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Solution { 7 | public: 8 | int maxProduct(vector& nums) { 9 | // O(N ** 2) 10 | int N = nums.size(); 11 | int result = 0; 12 | for (int i = 0; i < N; i++) 13 | for (int j = 0; j < N; j++) 14 | if (i != j) 15 | result = max(result, (nums[i] - 1) * (nums[j] - 1)); 16 | return result; 17 | } 18 | }; -------------------------------------------------------------------------------- /LeetCode/min-cost-climbing-stairs.cpp: -------------------------------------------------------------------------------- 1 | // 746. Min Cost Climbing Stairs 2 | #include 3 | #include 4 | #include 5 | 6 | class Solution { 7 | public: 8 | int minCostClimbingStairs(std::vector& cost) { 9 | // O(N) 10 | int N = cost.size(); 11 | for (int i = 2; i < N; i++) 12 | cost[i] += std::min(cost[i - 1], cost[i - 2]); 13 | return std::min(cost[N - 1], cost[N - 2]); 14 | } 15 | }; 16 | 17 | int main(void) { 18 | Solution s; 19 | } -------------------------------------------------------------------------------- /LeetCode/minimum-difference-between-highest-and-lowest-of-k-scores.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | class Solution { 8 | public: 9 | int minimumDifference(vector& nums, int k) { 10 | // O(N * log(N)) 11 | int N = nums.size(), result = INT_MAX; 12 | sort(nums.begin(), nums.end()); 13 | for (int i = 0; i <= N - k; i++) 14 | result = min(result, nums[i + k - 1] - nums[i]); 15 | return result; 16 | } 17 | }; -------------------------------------------------------------------------------- /LeetCode/minimum-moves-to-equal-array-elements.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Solution { 7 | public: 8 | int minMoves(vector& nums) { 9 | // O() 10 | int N = nums.size(); 11 | int result = 0; 12 | int Min = *min_element(nums.begin(), nums.end()); 13 | int Sum = accumulate(nums.begin(), nums.end(), 0); 14 | result = Sum - Min * N; 15 | return result; 16 | } 17 | }; -------------------------------------------------------------------------------- /LeetCode/minimum-operations-to-make-array-equal.cpp: -------------------------------------------------------------------------------- 1 | // 1551. Minimum Operations to Make Array Equal 2 | #include 3 | 4 | class Solution { 5 | public: 6 | int minOperations(int n) { 7 | // O(1) 8 | return (n / 2) * (n / 2 + n % 2); 9 | } 10 | }; 11 | 12 | int main(void) { 13 | Solution s; 14 | } -------------------------------------------------------------------------------- /LeetCode/mirror-reflection.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Solution { 4 | public: 5 | int mirrorReflection(int p, int q) { 6 | int gcd = __gcd(p, q); 7 | int l = p / gcd, r = q / gcd; 8 | if (l % 2 == 0) 9 | return 2; 10 | return r % 2 ? 1 : 0; 11 | } 12 | }; -------------------------------------------------------------------------------- /LeetCode/missing-number.cpp: -------------------------------------------------------------------------------- 1 | // 268. Missing Number 2 | #include 3 | #include 4 | 5 | class Solution { 6 | public: 7 | int missingNumber(std::vector& nums) { 8 | // O(N) 9 | int sum = 0, N = nums.size(); 10 | for (auto num : nums) 11 | sum += num; 12 | return N * (N + 1) / 2 - sum; 13 | } 14 | }; 15 | 16 | int main(void) { 17 | Solution s; 18 | } -------------------------------------------------------------------------------- /LeetCode/monotonic-array.cpp: -------------------------------------------------------------------------------- 1 | // 896. Monotonic Array#include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | bool isMonotonic(vector& nums) { 8 | // O(N) 9 | int l = 0, r = 0, N = nums.size(); 10 | for (int i = 0; i < N - 1; i++) { 11 | if (nums[i] <= nums[i + 1]) 12 | l++; 13 | if (nums[i] >= nums[i + 1]) 14 | r++; 15 | } 16 | return l == N - 1 || r == N - 1; 17 | } 18 | }; 19 | 20 | int main(void) { 21 | Solution s; 22 | } -------------------------------------------------------------------------------- /LeetCode/move-zeroes.cpp: -------------------------------------------------------------------------------- 1 | // 283. Move Zeroes 2 | #include 3 | #include 4 | 5 | class Solution { 6 | public: 7 | void moveZeroes(std::vector& nums) { 8 | // O(N) 9 | int k = 0; 10 | for (int i = 0; i < nums.size(); i++) 11 | if (nums[i] != 0) 12 | std::swap(nums[k++], nums[i]); 13 | } 14 | }; 15 | 16 | int main(void) { 17 | Solution s; 18 | std::vector nums {4, 12, 0, 3, 12}; 19 | s.moveZeroes(nums); 20 | for (auto &num : nums) 21 | std::cout << num << ' '; 22 | } -------------------------------------------------------------------------------- /LeetCode/n-th-tribonacci-number.cpp: -------------------------------------------------------------------------------- 1 | // 1137. N-th Tribonacci Number 2 | #include 3 | 4 | class Solution { 5 | public: 6 | int tribonacci(int n) { 7 | // O(N) 8 | int D[3] = {0, 1, 1}; 9 | if (n <= 2) 10 | return D[n]; 11 | for (int i = 0; i <= n - 3; i++) { 12 | int temp = D[0] + D[1] + D[2]; 13 | D[0] = D[1]; 14 | D[1] = D[2]; 15 | D[2] = temp; 16 | } 17 | return D[2]; 18 | } 19 | }; 20 | 21 | int main(void) { 22 | Solution s; 23 | } -------------------------------------------------------------------------------- /LeetCode/nim-game.cpp: -------------------------------------------------------------------------------- 1 | // 292. Nim Game 2 | #include 3 | 4 | class Solution { 5 | public: 6 | bool canWinNim(int n) { 7 | // O(1) 8 | return n % 4; 9 | } 10 | }; 11 | 12 | int main(void) { 13 | Solution s; 14 | } -------------------------------------------------------------------------------- /LeetCode/number-complement.cpp: -------------------------------------------------------------------------------- 1 | // 476. Number Complement 2 | #include 3 | 4 | class Solution { 5 | public: 6 | int findComplement(int num) { 7 | // O(1) 8 | int result = 0, i = 0; 9 | while (num > 0) { 10 | result |= !(num & 1) << i; 11 | num >>= 1; 12 | i += 1; 13 | } 14 | return result; 15 | } 16 | }; 17 | 18 | int main(void) { 19 | Solution s; 20 | int num = 2147483647; 21 | int result = s.findComplement(num); 22 | std::cout << result; 23 | } -------------------------------------------------------------------------------- /LeetCode/number-of-1-bits.cpp: -------------------------------------------------------------------------------- 1 | // 191. Number of 1 Bits 2 | #include 3 | #include 4 | 5 | class Solution { 6 | public: 7 | int hammingWeight(uint32_t n) { 8 | int result = 0; 9 | // O(log(n)) 10 | while (n > 0) { 11 | result += static_cast(n & 1); 12 | n >>= 1; 13 | } 14 | return result;; 15 | } 16 | }; 17 | 18 | int main(void) { 19 | Solution s; 20 | int result = s.hammingWeight(0b00); 21 | std::cout << result; 22 | } -------------------------------------------------------------------------------- /LeetCode/number-of-steps-to-reduce-a-number-to-zero.cpp: -------------------------------------------------------------------------------- 1 | // 1342. Number of Steps to Reduce a Number to Zero 2 | #include 3 | 4 | class Solution { 5 | public: 6 | int numberOfSteps (int num) { 7 | // O(log(N)) 8 | int result = 0; 9 | while (num) { 10 | if (num % 2) 11 | num--; 12 | else 13 | num >>= 1; 14 | result++; 15 | } 16 | return result; 17 | } 18 | }; 19 | 20 | int main(void) { 21 | Solution s; 22 | } -------------------------------------------------------------------------------- /LeetCode/orderly-queue.cpp: -------------------------------------------------------------------------------- 1 | // 899. Orderly Queue 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | class Solution { 9 | public: 10 | string orderlyQueue(string S, int K) { 11 | // O(N ** 2) 12 | if (K > 1) { 13 | sort(S.begin(), S.end()); 14 | return S; 15 | } 16 | string res = S; 17 | for (int i = 1; i < S.length(); i++) 18 | res = min(res, S.substr(i) + S.substr(0, i)); 19 | return res; 20 | } 21 | }; 22 | 23 | int main(void) { 24 | Solution s; 25 | } -------------------------------------------------------------------------------- /LeetCode/palindrome-number.cpp: -------------------------------------------------------------------------------- 1 | // 9. Palindrome Number 2 | #include 3 | 4 | class Solution { 5 | public: 6 | bool isPalindrome(int x) { 7 | // O(log(N)) 8 | long long X = static_cast(x), Y = 0; 9 | while (X > 0) { 10 | Y *= 10; 11 | Y += X % 10; 12 | X /= 10; 13 | } 14 | return x == Y; 15 | } 16 | }; 17 | 18 | int main(void) { 19 | Solution s; 20 | std::cout << s.isPalindrome(123333321); 21 | } -------------------------------------------------------------------------------- /LeetCode/partitioning-into-minimum-number-of-deci-binary-numbers.cpp: -------------------------------------------------------------------------------- 1 | // 1689. Partitioning Into Minimum Number Of Deci-Binary Numbers 2 | #include 3 | #include 4 | #include 5 | 6 | class Solution { 7 | public: 8 | int minPartitions(std::string n) { 9 | // O(N) 10 | int result = 0; 11 | for (auto c : n) 12 | result = std::max(result, c - '0'); 13 | return result; 14 | } 15 | }; 16 | 17 | int main(void) { 18 | Solution s; 19 | } -------------------------------------------------------------------------------- /LeetCode/patients-with-a-condition.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT 3 | patient_id, patient_name, conditions 4 | FROM Patients 5 | WHERE conditions LIKE '% DIAB1%' 6 | OR conditions LIKE 'DIAB1%'; 7 | -------------------------------------------------------------------------------- /LeetCode/poor-pigs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int poorPigs(int buckets, int minutesToDie, int minutesToTest) { 8 | // O(1) 9 | int result = ceil(log(buckets) / log(minutesToTest / minutesToDie + 1)); 10 | return result; 11 | } 12 | }; -------------------------------------------------------------------------------- /LeetCode/power-of-three.cpp: -------------------------------------------------------------------------------- 1 | // 326. Power of Three 2 | class Solution { 3 | public: 4 | bool isPowerOfThree(int n) { 5 | // O(log(N)) 6 | if (n <= 0) 7 | return false; 8 | while (n > 0) { 9 | if (n % 3 != 0) { 10 | if (n == 1) 11 | break; 12 | else 13 | return false; 14 | } 15 | n /= 3; 16 | } 17 | return true; 18 | } 19 | }; 20 | 21 | int main(void) { 22 | Solution s; 23 | } -------------------------------------------------------------------------------- /LeetCode/power-of-two.cpp: -------------------------------------------------------------------------------- 1 | // 231. Power of Two 2 | #include 3 | 4 | class Solution { 5 | public: 6 | bool isPowerOfTwo(int n) { 7 | return n >= 0 && __builtin_popcount(n) == 1; 8 | } 9 | }; 10 | 11 | int main(void) { 12 | Solution s; 13 | std::cout << s.isPowerOfTwo(256); 14 | } -------------------------------------------------------------------------------- /LeetCode/ransom-note.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Solution { 7 | public: 8 | bool canConstruct(string ransomNote, string magazine) { 9 | // O(N) 10 | unordered_map M; 11 | for (auto c : magazine) 12 | M[c]++; 13 | for (auto c : ransomNote) { 14 | M[c]--; 15 | if (M[c] < 0) 16 | return false; 17 | } 18 | return true; 19 | } 20 | }; -------------------------------------------------------------------------------- /LeetCode/rearrange-products-table.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT product_id, 'store1' as 'store', store1 as 'price' 3 | FROM Products WHERE store1 IS NOT NULL 4 | UNION 5 | SELECT product_id, 'store2' as 'store', store2 as 'price' 6 | FROM Products WHERE store2 IS NOT NULL 7 | UNION 8 | SELECT product_id, 'store3' as 'store', store3 as 'price' 9 | FROM Products WHERE store3 IS NOT NULL; 10 | -------------------------------------------------------------------------------- /LeetCode/recyclable-and-low-fat-products.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT product_id FROM Products 3 | WHERE low_fats = 'Y' 4 | AND recyclable = 'Y'; -------------------------------------------------------------------------------- /LeetCode/replace-all-digits-with-characters.cpp: -------------------------------------------------------------------------------- 1 | // 1844. Replace All Digits with Characters 2 | #include 3 | 4 | class Solution { 5 | public: 6 | std::string replaceDigits(std::string s) { 7 | int N = s.size(); 8 | for (int i = 0; i < N / 2; i++) 9 | s[2 * i + 1] = s[2 * i + 1] - '0' + s[2 * i]; 10 | return s; 11 | } 12 | }; 13 | 14 | int main(void) { 15 | Solution s; 16 | } -------------------------------------------------------------------------------- /LeetCode/reverse-words-in-a-string.py: -------------------------------------------------------------------------------- 1 | # 151. Reverse Words in a String 2 | 3 | class Solution: 4 | def reverseWords(self, s: str) -> str: 5 | # O(N) 6 | N = len(s) 7 | result = "" 8 | i = 0 9 | start, end = 0, 0 10 | while i <= N: 11 | if i == N or s[i] == " ": 12 | if i >= 1 and s[i - 1] != " ": 13 | result = s[start:end + 1] + " " + result 14 | start = end = i + 1 15 | else: 16 | end = i 17 | i += 1 18 | return result[:-1] -------------------------------------------------------------------------------- /LeetCode/richest-customer-wealth.cpp: -------------------------------------------------------------------------------- 1 | // 1672. Richest Customer Wealth 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | class Solution { 9 | public: 10 | int maximumWealth(vector>& accounts) { 11 | // O(M * N) 12 | int result = 0; 13 | for (auto account : accounts) { 14 | int sum = accumulate(account.begin(), account.end(), 0); 15 | result = max(result, sum); 16 | } 17 | return result; 18 | } 19 | }; 20 | 21 | int main(void) { 22 | Solution s; 23 | } -------------------------------------------------------------------------------- /LeetCode/rising-temperature.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT t2.id 3 | FROM Weather t1 4 | INNER JOIN Weather t2 5 | ON TIMESTAMPDIFF(DAY, t1.recordDate, t2.recordDate) = 1 AND t1.temperature < t2.temperature; 6 | -------------------------------------------------------------------------------- /LeetCode/running-sum-of-1d-array.cpp: -------------------------------------------------------------------------------- 1 | // 1480. Running Sum of 1d Array 2 | #include 3 | #include 4 | 5 | class Solution { 6 | public: 7 | std::vector runningSum(std::vector& nums) { 8 | // O(N) 9 | std::vector result; 10 | int sum = 0; 11 | for (auto num : nums) { 12 | sum += num; 13 | result.push_back(sum); 14 | } 15 | return result; 16 | } 17 | }; 18 | 19 | int main(void) { 20 | Solution s; 21 | } -------------------------------------------------------------------------------- /LeetCode/sales-analysis-iii.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | 3 | SELECT DISTINCT T.product_id, U.product_name 4 | FROM ( 5 | SELECT product_id 6 | FROM Sales 7 | WHERE product_id NOT IN ( 8 | SELECT product_id 9 | FROM Sales 10 | WHERE sale_date 11 | NOT BETWEEN CAST('2019-01-01' AS DATE) 12 | AND CAST('2019-03-31' AS DATE) 13 | ) 14 | ) AS T 15 | INNER JOIN Product as U 16 | ON U.product_id = T.product_id; 17 | -------------------------------------------------------------------------------- /LeetCode/sales-person.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT name 3 | FROM SalesPerson 4 | WHERE sales_id 5 | NOT IN ( 6 | SELECT DISTINCT sales_id 7 | FROM Orders 8 | WHERE com_id IN ( 9 | SELECT DISTINCT com_id 10 | FROM Company 11 | WHERE name = 'RED' 12 | ) 13 | ); 14 | 15 | -------------------------------------------------------------------------------- /LeetCode/second-highest-salary.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT IF(COUNT(*), salary, NULL) AS 'SecondHighestSalary' FROM 3 | ( 4 | SELECT DISTINCT salary 5 | FROM Employee 6 | ORDER BY salary 7 | DESC LIMIT 1, 1 8 | ) AS T; -------------------------------------------------------------------------------- /LeetCode/shift-2d-grid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | vector> shiftGrid(vector>& grid, int k) { 8 | // O(M * N) 9 | int M = grid.size(), N = grid[0].size(); 10 | vector > result (M, vector(N)); 11 | for (int i = 0; i < M * N; i++) { 12 | int cur = ((i - k) % (M * N) + M * N) % (M * N); 13 | result[i / N][i % N] = grid[cur / N][cur % N]; 14 | } 15 | return result; 16 | } 17 | }; -------------------------------------------------------------------------------- /LeetCode/single-number.cpp: -------------------------------------------------------------------------------- 1 | // 136. Single Number 2 | #include 3 | #include 4 | 5 | class Solution { 6 | public: 7 | int singleNumber(std::vector& nums) { 8 | // O(N) 9 | int result = 0; 10 | for (auto num : nums) 11 | result ^= num; 12 | return result; 13 | } 14 | }; 15 | 16 | int main(void) { 17 | Solution s; 18 | } -------------------------------------------------------------------------------- /LeetCode/smallest-index-with-equal-value.cpp: -------------------------------------------------------------------------------- 1 | // 2057. Smallest Index With Equal Value 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Solution { 7 | public: 8 | int smallestEqual(vector& nums) { 9 | // O(N) 10 | int N = nums.size(); 11 | for (int i = 0; i < N; i++) 12 | if (i % 10 == nums[i]) 13 | return i; 14 | return -1; 15 | } 16 | }; 17 | 18 | int main(void) { 19 | Solution s; 20 | } -------------------------------------------------------------------------------- /LeetCode/smallest-integer-divisible-by-k.cpp: -------------------------------------------------------------------------------- 1 | // 1015. Smallest Integer Divisible by K 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int smallestRepunitDivByK(int k) { 8 | // O(k) 9 | int sum = 0; 10 | int c = 1; 11 | for (int i = 1; i <= k; i++) { 12 | sum = (sum + c) % k; 13 | if (sum == 0) 14 | return i; 15 | c = 10 * c % k; 16 | } 17 | return -1; 18 | } 19 | }; 20 | 21 | int main(void) { 22 | Solution s; 23 | } -------------------------------------------------------------------------------- /LeetCode/sum-of-square-numbers.cpp: -------------------------------------------------------------------------------- 1 | // 633. Sum of Square Numbers 2 | #include 3 | #include 4 | 5 | class Solution { 6 | public: 7 | bool judgeSquareSum(int c) { 8 | // O(sqrt(c)) 9 | std::unordered_set cands; 10 | for (long long i = 0; i * i <= c; i++) 11 | cands.insert(i * i); 12 | for (auto cand : cands) 13 | if (cands.count(c - cand)) 14 | return true; 15 | return false; 16 | } 17 | }; 18 | 19 | int main(void) { 20 | Solution s; 21 | } -------------------------------------------------------------------------------- /LeetCode/swap-salary.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | UPDATE Salary 3 | SET sex = IF(sex = 'f', 'm', 'f'); -------------------------------------------------------------------------------- /LeetCode/the-latest-login-in-2020.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT user_id, MAX(time_stamp) AS 'last_stamp' 3 | FROM Logins 4 | WHERE EXTRACT(YEAR FROM time_stamp) = '2020' 5 | GROUP BY user_id; -------------------------------------------------------------------------------- /LeetCode/to-lower-case.cpp: -------------------------------------------------------------------------------- 1 | // 709. To Lower Case 2 | #include 3 | #include 4 | 5 | class Solution { 6 | public: 7 | std::string toLowerCase(std::string s) { 8 | // O(N) 9 | for (int i = 0; i < s.size(); i++) 10 | if ('A' <= s[i] && s[i] <= 'Z') 11 | s[i] += 'a' - 'A'; 12 | return s; 13 | } 14 | }; 15 | 16 | int main(void) { 17 | Solution s; 18 | } -------------------------------------------------------------------------------- /LeetCode/top-travellers.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT name, IFNULL(SUM(distance), 0) AS 'travelled_distance' 3 | FROM Users AS T 4 | LEFT JOIN Rides AS U 5 | ON T.id = U.user_id 6 | GROUP BY U.user_id 7 | ORDER BY travelled_distance DESC, name; 8 | -------------------------------------------------------------------------------- /LeetCode/transpose-matrix.cpp: -------------------------------------------------------------------------------- 1 | // 867. Transpose Matrix 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Solution { 7 | public: 8 | vector> transpose(vector>& matrix) { 9 | // O(M * N) 10 | int M = matrix.size(), N = matrix[0].size(); 11 | vector > result (N, vector(M)); 12 | for (int i = 0; i < M; i++) 13 | for (int j = 0; j < N; j++) 14 | result[j][i] = matrix[i][j]; 15 | return result; 16 | } 17 | }; 18 | 19 | int main(void) { 20 | Solution s; 21 | } -------------------------------------------------------------------------------- /LeetCode/tree-node.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT id, 'Root' as 'type' FROM Tree WHERE p_id IS NULL 3 | UNION 4 | SELECT id, 'Inner' as 'type' FROM Tree 5 | WHERE id IN (SELECT p_id FROM Tree GROUP BY p_id) AND p_id IS NOT NULL 6 | UNION 7 | SELECT id, 'Leaf' as 'type' FROM Tree 8 | WHERE id NOT IN (SELECT p_id FROM Tree WHERE p_id IS NOT NULL GROUP BY p_id) AND p_id IS NOT NULL 9 | ORDER BY id; -------------------------------------------------------------------------------- /LeetCode/unique-binary-search-trees.cpp: -------------------------------------------------------------------------------- 1 | // 96. Unique Binary Search Trees 2 | #include 3 | 4 | class Solution { 5 | public: 6 | int numTrees(int n) { 7 | // O(N) 8 | long long result = 1; 9 | for (int i = 0; i < n; i++) 10 | result = result * (2 * n - i) / (i + 1); 11 | result /= n + 1; 12 | return static_cast(result); 13 | } 14 | }; 15 | 16 | int main(void) { 17 | Solution s; 18 | int n = 5; 19 | std::cout << s.numTrees(n); 20 | } -------------------------------------------------------------------------------- /LeetCode/unique-email-addresses.py: -------------------------------------------------------------------------------- 1 | # 929. Unique Email Addresses 2 | from typing import List 3 | 4 | 5 | class Solution: 6 | def numUniqueEmails(self, emails: List[str]) -> int: 7 | # O(N) 8 | unique_emails = set() 9 | for email in emails: 10 | local_name, domain_name = email.split("@") 11 | local_name = local_name.replace(".", "") 12 | local_name = local_name.split("+")[0] 13 | unique_emails.add(f"{local_name}@{domain_name}") 14 | return len(unique_emails) -------------------------------------------------------------------------------- /LeetCode/user-activity-for-the-past-30-days-i.mysql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT activity_date as 'day', COUNT(DISTINCT user_id) as 'active_users' 3 | FROM Activity 4 | WHERE activity_date BETWEEN DATE_SUB('2019-07-27', INTERVAL 29 DAY) AND '2019-07-27' 5 | GROUP BY activity_date -------------------------------------------------------------------------------- /LeetCode/utils/.gitignore: -------------------------------------------------------------------------------- 1 | cred.py 2 | __pycache__/ 3 | *.csv 4 | -------------------------------------------------------------------------------- /LeetCode/utils/cred.py: -------------------------------------------------------------------------------- 1 | cred = "[CREDENTIALS:REDACTED] + [HEADERS:REDACTED]" 2 | -------------------------------------------------------------------------------- /LeetCode/utils/requirements.txt: -------------------------------------------------------------------------------- 1 | gitdb==4.0.9 2 | GitPython==3.1.27 3 | smmap==5.0.0 4 | -------------------------------------------------------------------------------- /LeetCode/verify-preorder-serialization-of-a-binary-tree.py: -------------------------------------------------------------------------------- 1 | # 331. Verify Preorder Serialization of a Binary Trees 2 | 3 | class Solution: 4 | def isValidSerialization(self, preorder: str) -> bool: 5 | # O(N) 6 | tokens = preorder.split(",") 7 | track = 1 8 | N = len(tokens) 9 | for i in range(N): 10 | if tokens[i] != "#": 11 | track += 1 12 | else: 13 | track -= 1 14 | if i != N - 1 and track == 0: 15 | return False 16 | result = track == 0 17 | return result -------------------------------------------------------------------------------- /LeetCode/water-and-jug-problem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | bool canMeasureWater(int jug1Capacity, int jug2Capacity, int targetCapacity) { 8 | // O(log(N)) 9 | int a = jug1Capacity, b = jug2Capacity, c = targetCapacity; 10 | if (a + b < c) 11 | return false; 12 | if (a == b) 13 | return a == c || 2 * a == c; 14 | int gcd = __gcd(a, b); 15 | return c % gcd == 0; 16 | } 17 | }; -------------------------------------------------------------------------------- /LeetCode/water-bottles.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Solution { 5 | public: 6 | int numWaterBottles(int numBottles, int numExchange) { 7 | // O(log(N)) 8 | int result = 0; 9 | int curFilled = numBottles; 10 | int curNotFilled = 0; 11 | while (curFilled > 0) { 12 | result += curFilled; 13 | curNotFilled += curFilled; 14 | curFilled = curNotFilled / numExchange; 15 | curNotFilled %= numExchange; 16 | } 17 | return result; 18 | } 19 | }; -------------------------------------------------------------------------------- /LeetCode/xor-operation-in-an-array.cpp: -------------------------------------------------------------------------------- 1 | // 1486. XOR Operation in an Array 2 | #include 3 | 4 | class Solution { 5 | public: 6 | int xorOperation(int n, int start) { 7 | // O(N) 8 | int result = 0; 9 | for (int i = 0; i < n; i++) 10 | result ^= (start + 2 * i); 11 | return result; 12 | } 13 | }; 14 | 15 | int main(void) { 16 | Solution s; 17 | } -------------------------------------------------------------------------------- /Misc/Complexity.md: -------------------------------------------------------------------------------- 1 | # Desired Time Complexity on `N` 2 | 3 | | size of `N` | Allowed Complexity | 4 | |:-:|:-:| 5 | | `N <= 11` | `O(N!)` | 6 | | `N <= 25` | `O(2 ** N)` | 7 | | `N <= 100` | `O(N ** 4)` | 8 | | `N <= 500` | `O(N ** 3)` | 9 | | `N <= 3000` | `O(N ** 2 * log(N))` | 10 | | `N <= 5000` | `O(N ** 2)` | 11 | | `N <= 1000000` | `O(N * log(N))` | 12 | | `N <= 10000000` | `O(N)` | 13 | | `N >= 10000000` | `O(log(N))`, `O(1)` | 14 | -------------------------------------------------------------------------------- /Misc/KMP/README.md: -------------------------------------------------------------------------------- 1 | # KMP 2 | 3 | KMP is basically DP. Two methods: 4 | 5 | - [DFA explanation](https://labuladong.gitbook.io/algo-en/i.-dynamic-programming/kmpcharactermatchingalgorithmindynamicprogramming) 6 | - [Using failure function](https://blog.encrypted.gg/857) 7 | 8 | Solving [Implement strStr()](https://leetcode.com/problems/implement-strstr/description/) 9 | - [kmp_dfa.cpp](kmp_dfa.cpp) 10 | 11 | Solving [찾기](https://www.acmicpc.net/problem/1786) 12 | - [kmp_failurefunction.cpp](kmp_failurefunction.cpp) 13 | 14 | -------------------------------------------------------------------------------- /Misc/SegmentTree/README.md: -------------------------------------------------------------------------------- 1 | # SegmentTree 2 | 3 | Solving [구간 합 구하기](https://www.acmicpc.net/problem/2042): mutable 4 | - [recursive.cpp](./recursive.cpp): [source](https://www.acmicpc.net/blog/view/9) 5 | - [iterative.cpp](./iterative.cpp) 6 | 7 | Solving [구간 합 구하기 2](https://www.acmicpc.net/problem/10999) 8 | - [recursive_lazy.cpp](./recursive_lazy.cpp): lazy propagation 9 | - iterative_lazy.cpp: TODO 10 | 11 | Great explanation on [codeforce](https://codeforces.com/blog/entry/18051) including lazy propagation. 12 | 13 | TODO: Reorganize source from upper article. -------------------------------------------------------------------------------- /Programmers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pcw109550/problem-solving/333d850a5261b49f32350b6a723c731156b24b8a/Programmers/.gitkeep -------------------------------------------------------------------------------- /Programmers/42578.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int solution(vector > clothes) { 9 | int answer = 1; 10 | unordered_map > M; 11 | for (auto cloth : clothes) { 12 | auto name = cloth[0]; 13 | auto type = cloth[1]; 14 | M[type].push_back(name); 15 | } 16 | for (auto it : M) 17 | answer *= it.second.size() + 1; 18 | answer -= 1; 19 | return answer; 20 | } 21 | 22 | int main(void) { 23 | } -------------------------------------------------------------------------------- /Programmers/42748.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | vector solution(vector array, vector > commands) { 9 | vector answer; 10 | for (auto cmd : commands) { 11 | vector temp = array; 12 | sort(temp.begin() + cmd[0] - 1, temp.begin() + cmd[1]); 13 | answer.emplace_back(temp[cmd[0] - 1 + cmd[2] - 1]); 14 | } 15 | return answer; 16 | } 17 | 18 | int main(void) { 19 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Problem-Solving 2 | 3 | ## Achievements 4 | 5 | - 2020.06.15: Solved 500 problems at Baekjoon. How long will it take to 1000? 6 | - 2020.11.14: Solved 100 problems at LeetCode. -------------------------------------------------------------------------------- /RUN/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pcw109550/problem-solving/333d850a5261b49f32350b6a723c731156b24b8a/RUN/.gitkeep -------------------------------------------------------------------------------- /RUN/2021/Spring_Contest/F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; cin >> N; 7 | int L = 1 << N; 8 | vector A (L); 9 | for (int i = 0; i < L; i++) 10 | cin >> A[i]; 11 | for (int i = 0; i < L; i++) 12 | for (int j = 1; j < L; j++) { 13 | if (A[i] + A[j] < A[i & j] + A[i | j]) { 14 | cout << i << ' ' << j; 15 | return 0; 16 | } 17 | } 18 | cout << -1; 19 | } -------------------------------------------------------------------------------- /RUN/2021/Spring_Contest/README.md: -------------------------------------------------------------------------------- 1 | # 2021 KAIST RUN Spring Contest 2 | 3 | Rank: 19th 4 | 5 | Score: 344 6 | 7 | [Problems](https://www.acmicpc.net/category/detail/2543) -------------------------------------------------------------------------------- /SWExpertAcademy/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pcw109550/problem-solving/333d850a5261b49f32350b6a723c731156b24b8a/SWExpertAcademy/.gitkeep -------------------------------------------------------------------------------- /SWExpertAcademy/8659.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | inline void printResult(int trial, long long a, long long b) { 5 | cout << '#' << trial << ' '; 6 | cout << a << ' ' << b << '\n'; 7 | } 8 | 9 | int main(void) { 10 | ios::sync_with_stdio(false); cin.tie(nullptr); 11 | int T; 12 | long long D[93] = {}; 13 | D[1] = 1; 14 | for (int i = 2; i <= 92; i++) { 15 | D[i] = D[i - 1] + D[i - 2]; 16 | } 17 | cin >> T; 18 | for (int t = 1; t <= T; t++) { 19 | int N; cin >> N; 20 | printResult(t, D[N + 2], D[N + 1]); 21 | } 22 | } -------------------------------------------------------------------------------- /UCPC/2020/Qual/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int a, b, c, d, e, f; 7 | cin >> a >> b >> c >> d >> e >> f; 8 | int D = a * e - b * d; 9 | int x = (e * c - b * f) / D; 10 | int y = (a * f - c * d) / D; 11 | cout << x << ' ' << y; 12 | } -------------------------------------------------------------------------------- /UCPC/2020/Qual/H.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | ios::sync_with_stdio(false); cin.tie(nullptr); 6 | int N; cin >> N; 7 | int target[N]; 8 | int cnt = 0, total = 0; 9 | for (int i = 0; i < N; i++) { 10 | cin >> target[i]; 11 | total += target[i]; 12 | cnt += target[i] / 2; 13 | } 14 | if (total % 3 != 0) { 15 | cout << "NO"; 16 | return 0; 17 | } 18 | cout << (total / 3 <= cnt ? "YES" : "NO"); 19 | } --------------------------------------------------------------------------------