Created
February 19, 2022 14:15
-
-
Save itmir913/d85b8de2ac8ae0b2017fad755eb02660 to your computer and use it in GitHub Desktop.
[OJ Code Template] 알고리즘 문제 풀 때 언어 별 코드 템플릿
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int main() { | |
| int a, b; | |
| cin >> a >> b; | |
| cout << a+b << endl; | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| public class Main { | |
| public static void main(String args[]) { | |
| Scanner scanner = new Scanner(System.in); | |
| int a, b; | |
| a = scanner.nextInt(); | |
| b = scanner.nextInt(); | |
| System.out.println(a + b); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Python Template | |
| import sys | |
| # input | |
| n = sys.stdin.readline() | |
| a, b = map(int, sys.stdin.readline().split()) | |
| # string format | |
| print("{} {}".format(10, 20)) | |
| # 1 in [1, 2] | |
| # 1 not in [1, 2] | |
| # list | |
| l = [1, 2, 3] | |
| len(l) | |
| l.append(4) | |
| l.insert(0, 5) | |
| l.extend([6, 7, 8]) | |
| ll = l + [1, 2, 3] | |
| del l[0] | |
| l.pop(0) | |
| index, value = enumerate(list) | |
| # dictionary | |
| dictionary = {"A": 10, "B": 20} | |
| A = dictionary["A"] | |
| dictionary["New"] = 30 | |
| # memoization | |
| memo = {1: 1, 2: 1} | |
| def fibonacci(n): | |
| if n in memo: | |
| return memo[n] | |
| result = fibonacci(n - 1) + fibonacci(n - 2) | |
| memo[n] = result | |
| return result | |
| # lambda function | |
| power = lambda x: x * x | |
| # with file open | |
| with open("text.txt", "w") as file: | |
| for line in file: | |
| # 파일 한 줄씩 읽기 | |
| pass | |
| pass | |
| # try - catch - finally | |
| try: | |
| pass | |
| except Exception as ex: | |
| # raise NotImplementedError | |
| pass # 예외 처리 코드 | |
| else: | |
| pass # 예외가 발생하지 않았을 때 처리 | |
| finally: | |
| pass # 무조건 실행 | |
| # private val : start with __ | |
| # getter setter with decorator | |
| class Circle: | |
| __radius = 0 | |
| @property | |
| def radius(self): | |
| return self.__radius | |
| @radius.setter | |
| def radius(self, value): | |
| if value <= 0: | |
| raise TypeError("radius is bigger then 0") | |
| self.__radius = value | |
| # map | |
| map(lambda x: x * x, [1, 2, 3]) | |
| # filter | |
| filter(lambda x: x < 3, [1, 2, 3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment