벡터 삭제하는 몇가지 방법 1. input 값 #include #include #include using namespace std; int main() { // index로 하나삭제 vector myvec = { 1,2,3,4,5,6 }; myvec.erase(myvec.begin() + 1); for (int i = 0; i < myvec.size(); i++) { cout 프로그래밍 문법/c++ 2020.06.21
printf 서식문자(%) [표 1] printf()함수의 서식 문자 구분 서식 문자 출력 형태 정수형 %d 10진수 정수 %x 16진수 정수 %c 문자 실수형 %f 10진수 실수 (float형) %e 10진수 실수 (지수형 표기) %lf 10진수 실수 (double형) 문자열 %s 문자열 출력 [표 2] printf()함수의 특수 제어 문자 문자 기능 \n 줄바꿈 \t 수평 탭(tab) \a ‘삑’하는 beep음을 발생한다. \\ 역슬래시 문자(\) 자체를 표시 \“ 따옴표 문자를 표시 출처: https://studymake.tistory.com/188 [스터디메이크] 프로그래밍 문법/c++ 2020.06.21
next_permutations 이용하여 순열, 조합구현 1. 순열 구현 int main (){ vector v; // 1부터 4까지 대입 for(int i=0; i 프로그래밍 문법/c++ 2020.06.21
벡터 역순정렬 #include //sort를 위해 #include //greater를 위해 sort(k.begin(), k.end(), greater() ); 프로그래밍 문법/c++ 2020.06.21
벡터에 요소있는지 확인 * vector에서 value가 있는 반복자를 리턴하는 함수(만약 value가 없다면 vector.end()까지 수행) #include vector::iterator iter; iter=find(vector.begin(),vector.end(),value); //만약 value 없다면 런타임에러 따라서 다음과 같은 식으로 value가 존재할 때 1, 없을때 0을 반환하게 할 수 있다. find(vector.begin(),vector.end(),value) != vector.end() 이는 파이썬에서 더보기 value in L 와 같다 프로그래밍 문법/c++ 2020.06.21
파이썬반올림 함수 round round(실수,n) : 실수를 반올림하여 소수점 n째자리 까지 나타낸 수 print(round(16.35,2)) print(round(16.35,1)) print(round(16.35,0)) print(round(16.35)) print(round(16.35,-1)) 더보기 16.35 16.4 16.0 16 20.0 프로그래밍 문법/python 2020.06.19
파이썬 입력 속도 빠르게 하기 1. input() 보다 sys.stdin.readline()을 이용한다 sys.stdin.readline() 이 속도가 빠르다. 하지만 \n까지 같이 입력받는다. 따라서 sys.stdin.readline().rstrip() 를 써서 개행을 제거하고 입력받는다. ex) import sys # 개행까지 함께 입력 a=sys.stdin.readline() print(a,"end") # 개행제외 함께 입력 b=sys.stdin.readline().rstrip() print(b,"end") 더보기 input input end input input end *c++은? https://blog.naver.com/ngoodsamari/221785816475 c++ 입출력 속도 빠르게하기 1. cin cout 입출력.. 프로그래밍 문법/python 2020.06.19
아스키코드 1. 문자를 아스키코드로 ord("A") 2. 아스키코드를 문자로 chr(65) 3. 아스키코드 기본적으로 (특수문자->숫자->대문자->소문자) 정도는 외울것 *키보드 위에서 아래로순서 프로그래밍 문법/python 2020.06.19
파이썬 진수변환 (10진수를 n진수로, n진수를 10진수로) 진수를 변환하는 방법은 다음과 같다 10진수를 n(2,8,16)진수로 바꾸는방법 10진수 x를 2진수로 바꾸려면 bin(x) , 10진수 x를 8진수로 바꾸려면 oct(x) 10진수 x를 16진수로 바꾸려면 hex(x) print(bin(11)) print(oct(11)) print(hex(11)) 타입은 모두 스트링 0b1011 (2진법은 앞에 0b가 붙는다) 0o13 (8진법은 앞에 0o가 붙는다) 0xb (16진법은 앞에 0x가 붙는다) * 2,8,16 진수가 아닌 다른 진수로 바꾸고 싶으면 다음 함수를 이용한다. def convert(n, base): ''' n: base진수로 바꿀 10진수 base : 진수 ''' q, r = divmod(n, base) if q == 0: return str(.. 프로그래밍 문법/python 2020.06.19
[파이썬] 2차원리스트 dictionary형으로 바꾸기 2차원으로 구성된 자료형은 dictionary형으로 바꿀 수 있다. L1=[[1,2],[54,5]] L2=[(3,5),(6,7)] L3=([1,2],(7,8)) tempD1=dict(L1) tempD2=dict(L2) tempD3=dict(L3) print(tempD1) print(tempD2) print(tempD3) 더보기 {1: 2, 54: 5} {3: 5, 6: 7} {1: 2, 7: 8} 프로그래밍 문법/python 2020.06.19
aliasing시 요소 수정과 재정의의 차이 리스트를 aliasing(b=t)했을 때 1. 리스트 자체를 재정의 하면 수정이 적용되지 않지만 2. 요소를 수정하면 수정이 적용된다 print("[리스트를 재정의]") b=[] t=[1,2,3] b=t print("전") print(b) t=[5,6,7] print("후") print(b) print() print("리스트 요소 수정") b=[] t=[1,2,3] b=t print("전") print(b) t[0]=5 t[1]=6 t[2]=7 print("후") print(b) 더보기 [리스트를 재정의] 전 [1, 2, 3] 후 [1, 2, 3] 리스트 요소 수정 전 [1, 2, 3] 후 [5, 6, 7] 프로그래밍 문법/python 2020.06.19
입력받는 함수 input() # 공백을 기준으로 나누어서 리스트로 저장 input().split() # n으로 구분되어 나누어서 리스트로 저장 input().split("n") # 한글자씩 끊어서 입력받음 (엔터치기 전까지 입력된 모든값들을 str 타입으로 저장) input().strip() 프로그래밍 문법/python 2020.06.19
자료형 자료형 Collection Mutable Ordered Duplication Notation Description Empty Collection string no yes yes " " "simple string" s = '' or s = "" list yes yes yes [ ] [ ["item0_0", 12 ], ["item1_0", 22 ] ] l = [] tuple no yes yes ( ) ( ["item0_0", 12 ], ["item1_0", 22 ] ) t = () set yes no no { } { 1, 2, 3, 4, 5 } S = set() dictionary yes no no { } { 'one' : 1, 'two' : 2, 'three' : 3 } d = {} 프로그래밍 문법/python 2020.06.19
람다(lambda)함수 사용법 lambda (함수이름없이 익명으로 함수사용가능, 한번사용할 때 용이) ( lambda [매개변수]: 리턴값을 포함한 알고리즘 )( [매개변수 값] ) a = (lambda foo: foo * 2)(10) = print(a) => 20 프로그래밍 문법/python 2020.06.19
큐 (queue) # 선언 q=queue.Queue() # 넣기 q.put("요소") # 빼기 q.get() # 비어있는지 확인 q.empty() # 사이즈 확인 q.qsize() import queue q=queue.Queue() # > q.put("apple") q.put("banana") print(q.qsize()) while(not q.empty()): print(q.get()) # 혹은 q.put("apple") q.put("banana") print(q.qsize()) while(q.qsize()): print(q.get()) 더보기 2 apple banana 2 apple banana 프로그래밍 문법/python 2020.06.19