본문 바로가기

분류 전체보기

(82)
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 #include #include #include #include using namespace std; int prime[101]; int ints[101]; string s[101]; bool isPrime(int x){ int chk; if (x >= 2){ chk = 0; for (int i = 2; i > n; int temp; for (int i = 0; i > s[i]; temp = reverse(stoi..
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]..
C++ 1 ~ N 까지의 약수 개수 (1과 자기자신 포함) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #include using namespace std; int cnt[50001]; int main(){ int i, j, n; scanf("%d", &n); for (i = 1; 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))
[백준] 10773 제로 Python C++ 1 2 3 4 5 6 7 8 9 n = int(input()) result = [] for i in range(n): inputs = int(input()) if inputs == 0: result.pop() else: result.append(inputs) print(sum(result)) 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 38 39 40 41 #include #include #include #include #include #include #include #include #include #include using namespace std; int main(..
[백준] 11047 동전0 Python 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 n, k = map(int, input().strip().split()) inputs = [] cnt = 0 point = 0 temp = 0 for i in range(n): temp = int(input()) inputs.append(temp) if temp > k; int *inputs = new int[n]; for (int i = 0; i > *(inputs + i); if (k >= *(inputs + i)) point = i; //cout