본문 바로가기

Programming Language

(20)
C++ 가장 많이 사용된 자리의 수 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 #include #include #include #include using namespace std; int main(){ int temp = 0, max_nums = 0, max_cnt = 0, i=0; string s; cin >> s; int s_length = s.size(); int *arr = new int[s_length]; for (char c : s){ arr[i] = (int)c-48; i++; } for (int i = 0; i max_cnt){ max_cnt = temp; max_nums = arr[i]..
Python 순열(Permutation) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 # 1 ~ n 까지의 숫자가 있을 때 나열할 수 있는 경우의 수 혹은 경우 def perm(a): length = len(a) if length == 1: return [a] else: result = [] for i in a: b = a.copy() b.remove(i) b.sort() for j in perm(b): j.insert(0, i) if j not in result: result.append(j) return result if __name__ == "__main__": num = int(input('1부터 n까지 자연수를 나열하는 순열을 구합니다. n 을 입력하세요 : ')) a..
Python itertools를 이용한 순열과 조합 (combinations, permutations) 1 2 3 4 5 6 7 8 9 10 11 12 13 import itertools abc = [1,2,3,4] #abc = ['a','b','c','d'] b = itertools.permutations(abc, 3) #target, length(Non-Essential) for i in b: #i = list(i) print(list(i)) b = itertools.combinations(abc, 2) #target, length(Essential) for i in b: #i = list(i) print(list(i))
Python String copy 1 2 3 4 5 6 7 8 9 # variable a and b id equal a = "python" b = a print(id(a)) print(id(b),"\n") b = (a+".")[:-1] # python string slice print(id(a)) print(id(b))
Python Dictionary Max, Min Key, Value(파이썬 딕셔너리, 사전 최대 최소 구하기) 1 2 3 4 5 6 dicts = {"c":1, "b":2, "a":3} print("dicts의 최대 값 구하기: {}".format(max(dicts.values()))) print("dicts의 최소 값 구하기: {}".format(min(dicts.values()))) print("dits의 최대 값을 가지는 key 구하기: {}".format(max(dicts, key=dicts.get))) print("dits의 최소 값을 가지는 key 구하기: {}".format(min(dicts, key=dicts.get))) cs
C++ Template Function 1234567891011121314151617 #include using namespace std; template void abc(T n1, T1 n2){ cout
문자열 입력 Python 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071721) 문자열 입력 받은 후 공백 기준 파싱2) 숫자 엔터 구분 3) 문자 엔터구분 4) 문자열 엔터구분5) N by N6) N by M 1) 공백 구분 입력 받기 N = list(map(str input().strip().split())) 2) 숫자 엔터구분 입력받기 cnt = int(input())strs = ""lists = [] for i in range(cnt): N = int(input()) strs.append(N) lists.append(N) print(..
C++ 최소값(min), 최대값(max) 그리고 minmax() 123456789101112131415161718192021222324 #include #include using namespace std; int main(){ // min, max, minmax 는 #include 필요 그리고 자료형은 auto라는 점을 주의 // min, max의 경우 인자를 2개로 받음 auto result = min(1, 2); auto result2 = min(2, 3); cout