From f64e17064c5e83c66155d0dbb341de0b728bc12c Mon Sep 17 00:00:00 2001 From: beombu Date: Wed, 26 Jan 2022 22:28:42 +0900 Subject: [PATCH 1/8] add python tip&String_manipulation.md --- 01/beom/String_Manipulation.md | 42 +++++++ 01/beom/algorithm_tip_python.md | 197 ++++++++++++++++++++++++++++++++ 2 files changed, 239 insertions(+) create mode 100644 01/beom/String_Manipulation.md create mode 100644 01/beom/algorithm_tip_python.md diff --git a/01/beom/String_Manipulation.md b/01/beom/String_Manipulation.md new file mode 100644 index 00000000..e41b7227 --- /dev/null +++ b/01/beom/String_Manipulation.md @@ -0,0 +1,42 @@ +# 문자열 조작 + +## 문자열 처리 관련 알고리즘이 사용되는 분야 +1. 정보 처리 분야 : 어떤 키워드로 웹 페이지를 탐색할 경우 +2. 통신 시프템 분야 : 문자메시지나 이메일을 보낼 경우 +3. 프로그래밍 시스템 분야 : 컴파일이나 인터프리터가 문자열을 해석하고 처리하여 기계어로 변환하는 경우 + +## 1. 유효한 팰린드롬(Valid Palindrome) +팰랜드롬 : 앞뒤가 똑같은 단어나 문장으로, 뒤집어도 같은 말이 되는 단어 또는 문장 + +### 풀이 서술 +1. 대소문자를 구분하지 않기 때문에 lower() 사용 +2. 뛰어 쓰기를 없어주어야함 +3. 자료구조 Dequeue에 넣고 +4. 앞 뒤 를 비교하여 다 맞으면 true 틀리면 false + +### 코드 +- 코딩 미숙으로 예제 코드를 인용함 + +```python3 +from collections import deque + +def Palindrome(s:str) -> bool: + strs = deque() + + for char in s: + if char.isalnum(): + strs.append(char.lower()) + + while len(strs) > 1: + if strs.popleft() != strs.pop(): + print(False) + return False + + print(True) + return True + +a = input() + +Palindrome(a) +``` + diff --git a/01/beom/algorithm_tip_python.md b/01/beom/algorithm_tip_python.md new file mode 100644 index 00000000..b36c5338 --- /dev/null +++ b/01/beom/algorithm_tip_python.md @@ -0,0 +1,197 @@ +# 파이썬 코딩 테스트 Tip! +파이썬 코딩 테스트를 위해 사전작업 + + +## 리스트 원소를 출력할 떄 join 사용하기 +```python3 +# 안좋은예: + 로 string 잇기 +mymsg=[‘line1’,’line2’] +for msg in mymsg : + word += msg+ ' ' + +# 더 나은 선택 +mymsg=[‘line1’,’line2’] +‘ ’.join(mymsg) +``` + +## 문자열에 + 연산자 피하기 +```python3 +# 안좋은 예 +msg = ’hello’ + mymsg + ’world’ + +# 더 나은 선택 +msg = f'hello {mymsg} world' +``` + +## 제너레이터(Generaotr) 사용하기 +- Generator : iterator 를 생성해 주는 함수 + - iterator : next() 메서드를 이용해 데이터에 순차적으로 접근이 가능한 객체 + +**제너레이터 사용이유** +1. 메모리를 효율적으로 사용 #list에 경우 사이즈가 커질수록 메모리 사용량이 늘어남. 반면, generator의 경우 사이즈가 커져도 차지하는 메모리 사이즈는 동일 +2. Lazy Evaluation 효과를 볼 수 있다. #Lazy Evaluation: 계산 결과값이 필요할 때까지 계산을 늦추는 효과 + +```python3 +def generator(n): + i = 0 + while i < n: + yield i + i += 1 + +for x in generator(5): + print(x) + +# 출력 +0 +1 +2 +3 +4 +``` + +[제너레이터 링크](https://milhouse93.tistory.com/159) + +## 파이썬에서 코드 성능 확인하는 법 +- cProfile 및 프로파일과 같은 프로파일링 모듈 사용 + +```python3 +python -m cProfile [-o output_file][-s sort_order](-m module | myscript.py) +``` + +## 풀제풀이에 도움되는 메서드 +```python3 +# 소수점 내림, 올림 +from math floor, ceil +floor(), ceil() + +# comparator 함수로 정렬 조건을 정함 +from functools import cmp_to_key +sorted(lst, key=cmp_to_key(comparator)) +# 정렬 조건이 두 개일때 이렇게도 가능하다 +lambda x : (x[0], -x[1]) + +# out of index 피하는 방법 +if a[-1:] == [i]: + +# 진수 변환, 문자열 반환 +format(42, 'b') + +# 문자열 알파벳 모두 소문자로, 대문자로 변경, 반전 +islower(), isupper(), swapcase() + +# 아스키->문자, 문자->아스키 +chr(), ord() + +# permutations : 순열, 중복 허용 X +# product : 순열, 중복 허용 O +# combinations : 조합, 중복 허용 X +# combinations_with_replacement : 조합, 중복 허용 O +from itertools import permutations, combinations, product +p = list(permutations(lst, 2)) +p = list(product(lst, repeat=2)) +p = list(combinations(lst, 2)) +p = list(combinations_with_replacement(lst, 2)) + +# (몫, 나머지) 튜플 리턴 +divmod(나눠지는 수, 나누는 수) + +# 알파벳으로만 되어있는지, 숫자로만 되어있는지 참,거짓 반환 +isalpha(), isdigit() + +# 자리 수(인자 값) 만큼 0으로 채움 +"123".zfill(5) 은 "00123" 반환 +# 자리 수(첫번째 인자 값) 만큼 두번째 인자값으로 채움 +"123".rjust(5, "a") 은 "aa123" 반환 +# 위와 같은 방법으로 왼쪽 정렬, 가운데 정렬 +ljust(), center() + +# 덱을 생성할 때 최대 길이를 설정할 수 있다. +from collections import deque +# 스택 구현 +append(), pop() +# 큐 구현 +appendleft(), pop(), append(), popleft() +# deque 확장 +extend(), extendleft() +# list 처럼 사용, remove는 왼쪽부터 제거 +insert(), remove() +dq.insert(0, 'K') +# 내용 반전 +reverse() + +# 요소들의 개수를 세서 딕셔너리 형태로 담아줌 +from collections import Counter +# 가장 많이 출현한 키를 n개 까지 찾아준다 +most_common(n) +# 덧셈 뺄셈이 가능, &(교집합)과 |(합집합)도 가능 +# 뺄셈의 경우 사라지지 않고 마이너스로 표현하고 싶을 경우 +a.subtract(b) 마이너스로도 나타내줌 +# 카운터 숫자만큼 요소들 반환 +elements() + +# 순서가 있는 딕셔너리 +from collections import OrderedDict +# 인자 X 혹은 last=true 라고 주면 마지막 값을 리턴하고 제거 +ordered_dict.popitem() +# last=False 라고 주면 첫번째 값을 리턴하고 제거 +ordered_dict.popitem(last=False) +# 한꺼번에 딕셔너리 생성 +od = OrderedDict.fromkeys('red') 으로 생성하면 OrderedDict([('r', None), ('e', None), ('d', None)]) +# 'r'키값을 제일 마지막으로 이동 +od.move_to_end('r') +# 'r'키값을 제일 처음으로 이동 +od.move_to_end('r', last=False) + +# %s 에 'Bob'을 넣음 +'Hello %s' % 'Bob' + +# 문자열의 첫글자만 대문자로 변경, 문자열의 모든 단어들의 첫글자를 대문자로 변경 +capitalize(), title() + +# 문자열 대치 'a'를 'b'로 바꾸는데 2번째까지만 바꿈 +replace('a','b',2) + +# 재귀 제한 늘리기 +import sys +sys.setrecursionlimit(10**6) + +# 날짜 관련 +from datetime import datetime, timedelta +dt = datetime.strptime('2018/02/22 10:56','%Y/%m/%d %H:%M:%S.%f') +another_year = timedelta(weeks=40, days=84, hours=23, minutes=50, seconds=600) +d.strftime('%Y-%m-%d %H:%M:%S') # 날짜/시간 객체를 문자열로 만들기 +``` + +## 테스트 케이스 입력 방법 +```python3 +input() + +import sys +sys.stdin.readline().rsplit('\n') +``` +1. input과 sys.stdin.readline().rsplit('\n') 두가지 방법으로 테스트 케이스를 입력하는데 후자가 더 빠름 + +**정수를 입력 받을 경우** +```python3 +a, b = map(int, input().split()) +``` + +[참고 링크](https://phil-baek.tistory.com/entry/%EC%BD%94%ED%85%8C-%ED%8C%8C%EC%9D%B4%EC%8D%AC-Use-case-%EC%A0%95%EB%A6%AC) + +## 시간, 공간 복잡도 관련 팁 +```python3 +import time +start_time = time.time() + +# 프로그램 작성 +end_time = time.time() +print("time :", end_time - start_time) +``` + +[참고 링크](https://kih0902.tistory.com/35) + + + + +## 참고 문헌 +[코드 성능 확인까지의 참고문헌](https://velog.io/@swhan9404/%ED%8C%8C%EC%9D%B4%EC%8D%AC-%EB%A9%94%EB%AA%A8%EB%A6%AC-%EA%B4%80%EB%A6%AC%EA%B3%BC-%ED%9A%A8%EC%9C%A8%EC%A0%81%EC%9D%B8-%EC%BD%94%EB%93%9C) \ No newline at end of file From 68097d47718d725700c44316f6acb8580b3fce76 Mon Sep 17 00:00:00 2001 From: beombu Date: Thu, 27 Jan 2022 00:44:05 +0900 Subject: [PATCH 2/8] =?UTF-8?q?add=20codeUp=2050=EB=B2=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 01/beom/codeup_java.md | 657 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 657 insertions(+) create mode 100644 01/beom/codeup_java.md diff --git a/01/beom/codeup_java.md b/01/beom/codeup_java.md new file mode 100644 index 00000000..a592f267 --- /dev/null +++ b/01/beom/codeup_java.md @@ -0,0 +1,657 @@ +# codeup 기초 100제 java편 + +## 1번 +```java +public class Main { + public static void main(String[] args) { + System.out.println("Hello"); + } +} +``` + +## 2번 +```java +public class Main { + public static void main(String[] args) { + System.out.println("Hello World"); + } +} +``` + +## 3번 +```java +public class Main { + public static void main(String[] args) { + System.out.println("Hello\nWorld"); + } +} +``` + +## 4번 +```java +public class Main { + public static void main(String[] args) { + System.out.println("'Hello'"); + } +} +``` + +## 5번 +```java +public class Main { + public static void main(String[] args) { + System.out.println("\"Hello World\""); + } +} +``` + +## 6번 +```java +public class Main { + public static void main(String[] args) { + System.out.println("\"!@#$%^&*()\""); + } +} +``` + +## 7번 +```java +public class Main { + public static void main(String[] args) { + System.out.println("\"C:\\Download\\hello.cpp\""); + } +} +``` + +## 8번 +```java +public class Main { + public static void main(String[] args) { + System.out.println("\u250c\u252c\u2510"); + System.out.println("\u251c\u253c\u2524"); + System.out.println("\u2514\u2534\u2518"); + } +} +``` + +## 10번 +``'java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println(sc.next()); + } +} +``` + +## 11번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println(sc.next().charAt(0)); + } +} +``` + +## 12번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + float a = sc.nextFloat(); + sc.close(); //Scanner종료 자원해제 + System.out.printf("%f\n",a); + } +} +``` +## 13번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a = sc.nextInt(); + int b = sc.nextInt(); + sc.close(); //Scanner종료 자원해제 + System.out.printf(a+" "+b); + } +} +``` + +## 14번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + char a = sc.next().charAt(0); + char b = sc.next().charAt(0); + sc.close(); //Scanner종료 자원해제 + System.out.printf(b+" "+a); + } +} +``` + +## 15번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + float a = sc.nextFloat(); + sc.close(); //Scanner종료 자원해제 + System.out.printf("%.2f",a); + } +} +``` + +## 17번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a = sc.nextInt(); + sc.close(); //Scanner종료 자원해제 + System.out.printf(a + " " + a + " " + a); + } +} +``` + +## 18번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + String a = sc.next(); + String[] b = a.split(":"); + sc.close(); //Scanner종료 자원해제 + System.out.printf("%d:%d",Integer.parseInt(b[0]),Integer.parseInt(b[1])); + } +} +``` + +## 19번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + String u = sc.next(); + StringTokenizer a = new StringTokenizer(u,"."); + int[] b = new int[3]; + int i=0; + while(a.hasMoreTokens()){ + b[i]=Integer.parseInt(a.nextToken()); + i++; + } + sc.close(); //Scanner종료 자원해제 + System.out.printf("%04d.%02d.%02d",b[0],b[1],b[2]); + } +} +``` + +### 20번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + String a = sc.next(); + String[] b = a.split("-"); + System.out.printf("%s%s",b[0],b[1]); + } +} +``` + +## 21번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + String a = sc.next(); + System.out.println(a); + } +} +``` + +## 22번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + String a = sc.nextLine(); + System.out.println(a); + } +} +``` + +## 23번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + String a = sc.next(); + String[] b = a.split("\\."); + System.out.printf("%s\n%s",b[0],b[1]); + } +} +``` + +## 24번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + String a = sc.next(); + String[] b = a.split(""); + for(int i=0;ib){ + System.out.println(1); + } + else{ + System.out.println(0); + } + } +} +``` + +## 50번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a =sc.nextInt(); + int b = sc.nextInt(); + + if(a==b){ + System.out.println(1); + } + else{ + System.out.println(0); + } + } +} +``` From 2d29eb1c48b3ff18f9b65a7f2900a8211f718a52 Mon Sep 17 00:00:00 2001 From: beombu Date: Thu, 27 Jan 2022 13:56:33 +0900 Subject: [PATCH 3/8] add code up 58 --- 01/beom/codeup_java.md | 172 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) diff --git a/01/beom/codeup_java.md b/01/beom/codeup_java.md index a592f267..89e5bde1 100644 --- a/01/beom/codeup_java.md +++ b/01/beom/codeup_java.md @@ -655,3 +655,175 @@ public class Main { } } ``` + +## 51번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a =sc.nextInt(); + int b = sc.nextInt(); + + if(a<=b){ + System.out.println(1); + } + else{ + System.out.println(0); + } + } +} +``` + +## 52번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a =sc.nextInt(); + int b = sc.nextInt(); + + if(a!=b){ + System.out.println(1); + } + else{ + System.out.println(0); + } + } +} +``` + +## 53번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a =sc.nextInt(); + + if(a==0){ + System.out.println(1); + } + else{ + System.out.println(0); + } + } +} +``` +## 54번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a =sc.nextInt(); + int b = sc.nextInt(); + + if(a==1 && b==1){ + System.out.println(1); + } + else{ + System.out.println(0); + } + } +} +``` + +## 55번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a =sc.nextInt(); + int b = sc.nextInt(); + + if(a==1 || b==1){ + System.out.println(1); + } + else{ + System.out.println(0); + } + } +} +``` + +## 56번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a =sc.nextInt(); + int b = sc.nextInt(); + + if((a==1 && b==0)||(a==0&&b==1)){ + System.out.println(1); + } + else{ + System.out.println(0); + } + } +} +``` + +## 57번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a =sc.nextInt(); + int b = sc.nextInt(); + + if((a==1 && b==1)||(a==0&&b==0)){ + System.out.println(1); + } + else{ + System.out.println(0); + } + } +} +``` + +## 58번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a =sc.nextInt(); + int b = sc.nextInt(); + + if((a==0&&b==0)){ + System.out.println(1); + } + else{ + System.out.println(0); + } + } +} +``` + +## 59번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a =sc.nextInt(); + + System.out.println(~a); + } +} +``` From 84148401d3bc41a779b50f874ebce011357dac4f Mon Sep 17 00:00:00 2001 From: beombu Date: Thu, 27 Jan 2022 17:09:18 +0900 Subject: [PATCH 4/8] add codeup 84 --- 01/beom/codeup_java.md | 523 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 523 insertions(+) diff --git a/01/beom/codeup_java.md b/01/beom/codeup_java.md index 89e5bde1..15ad58a9 100644 --- a/01/beom/codeup_java.md +++ b/01/beom/codeup_java.md @@ -827,3 +827,526 @@ public class Main { } } ``` + +## 60번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a =sc.nextInt(); + int b = sc.nextInt(); + + System.out.println(a&b); + } +} +``` + +## 61번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a =sc.nextInt(); + int b = sc.nextInt(); + + System.out.println(a|b); + } +} +``` + +## 62번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a =sc.nextInt(); + int b = sc.nextInt(); + + System.out.println(a^b); + } +} +``` + +## 63번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a =sc.nextInt(); + int b = sc.nextInt(); + + System.out.printf("%d",a>b ? a:b); + } +} +``` + +## 64번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a =sc.nextInt(); + int b = sc.nextInt(); + int c = sc.nextInt(); + + System.out.printf("%d",(a>b ? b:a)>c? c:(a>b ? b:a)); + } +} +``` + +## 65번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a =sc.nextInt(); + int b = sc.nextInt(); + int c = sc.nextInt(); + + if(a%2 ==0){ + System.out.println(a); + } + if(b%2 ==0){ + System.out.println(b); + } + if(c%2 ==0){ + System.out.println(c); + } + } +} +``` + +## 66번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a =sc.nextInt(); + int b = sc.nextInt(); + int c = sc.nextInt(); + + if(a%2 ==0){ + System.out.println("even"); + } + else{ + System.out.println("odd"); + } + if(b%2 ==0){ + System.out.println("even"); + } + else{ + System.out.println("odd"); + } + if(c%2 ==0){ + System.out.println("even"); + } + else{ + System.out.println("odd"); + } + } +} +``` + +## 67번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a =sc.nextInt(); + + + if(a>0){ + System.out.println("plus"); + if(a%2==0){ + System.out.println("even"); + } + else { + System.out.println("odd"); + } + } + else{ + System.out.println("minus"); + if(a%2==0){ + System.out.println("even"); + } + else { + System.out.println("odd"); + } + } + } +} +``` + +## 68번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a = sc.nextInt(); + + + if (a >= 90) { + System.out.println("A"); + } else if (a >= 70) { + System.out.println("B"); + } else if (a >= 40) { + System.out.println("C"); + } else { + System.out.println("D"); + } + } +} +``` + +## 69번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + String a = sc.nextLine(); + + switch (a) { + case "A": { + System.out.println("best!!!"); + break; + } + case "B": { + System.out.println("good!!"); + break; + } + case "C": { + System.out.println("run!"); + break; + } + case "D": { + System.out.println("slowly~"); + break; + } + default: + System.out.println("what?"); + break; + } + } +} +``` + +## 70번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a = sc.nextInt(); + + switch (a) { + case 12: + System.out.println("winter"); + break; + case 1: + System.out.println("winter"); + break; + case 2: + System.out.println("winter"); + break; + case 3: + System.out.println("spring"); + break; + case 4: + System.out.println("spring"); + break; + case 5: + System.out.println("spring"); + break; + case 6: + System.out.println("summer"); + break; + case 7: + System.out.println("summer"); + break; + case 8: + System.out.println("summer"); + break; + case 9: + System.out.println("fall"); + break; + case 10: + System.out.println("fall"); + break; + case 11: + System.out.println("fall"); + break; + } + } +} +``` + +## 71번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + while(true){ + int a = sc.nextInt(); + if(a!=0){ + System.out.println(a); + } + else{ + break; + } + } + } +} +``` + +## 72번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + while (true){ + int a = sc.nextInt(); + if(a==0){ + break; + } + else{ + System.out.println(a); + } + } + } +} +``` + +## 74번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a = sc.nextInt(); + while (a!=0){ + System.out.println(a); + a--; + } + } +} +``` + +## 75번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a = sc.nextInt(); + while (a!=0){ + System.out.println(a-1); + a--; + } + } +} +``` + +## 76번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + char a = sc.next().charAt(0); + char b = 'a'; + while (b<=a){ + System.out.print(b+" "); + b++; + } + } +} +``` + +## 77번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a = sc.nextInt(); + int b = 0; + while (a>=b){ + System.out.println(b); + b++; + } + } +} +``` + +## 78번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a = sc.nextInt(); + int sum = 0; + + for(int i=0;i<=a;i++){ + if(i%2==0) { + sum = sum + i; + } + } + System.out.println(sum); + } +} +``` + +## 79번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + while(true){ + char a = sc.next().charAt(0); + if(a=='q'){ + System.out.println(a); + break; + } + else { + System.out.println(a); + } + } + } +} +``` + +## 80번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a = sc.nextInt(); + int b=1; + int sum =0; + while (true){ + sum = sum+b; + if(sum>=a){ + System.out.println(b); + break; + } + b++; + } + } +} +``` + +## 81번 +```java +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a = sc.nextInt(); + int b = sc.nextInt(); + for(int i = 0; i Date: Sun, 30 Jan 2022 23:38:10 +0900 Subject: [PATCH 5/8] fininsh codeup --- 01/beom/codeup_java.md | 84 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/01/beom/codeup_java.md b/01/beom/codeup_java.md index 15ad58a9..bddc1a09 100644 --- a/01/beom/codeup_java.md +++ b/01/beom/codeup_java.md @@ -1350,3 +1350,87 @@ public class Main { } ``` +## 85번 +```java +import java.util.*; + +class Main { + public static void main(String args[]) { + Scanner sc = new Scanner(System.in); + double h = sc.nextInt(); + double b = sc.nextInt(); + double c = sc.nextInt(); + double s = sc.nextInt(); + + double result = (h*b*c*s)/1024/1024/8; + System.out.printf("%.1f MB",result); + + } +} +``` + +## 86번 +```java +import java.util.*; + +class Main { + public static void main(String args[]) { + Scanner sc = new Scanner(System.in); + double w = sc.nextInt(); + double h = sc.nextInt(); + double b = sc.nextInt(); + + double result = (w*h*b)/1024/1024/8; + System.out.printf("%.2f MB",result); + + } +} +``` + +## 87번 +```java +import java.util.*; + +class Main { + public static void main(String args[]) { + Scanner sc = new Scanner(System.in); + int a = sc.nextInt(); + int i=0; + int b = 1; + while(true){ + i=i+b; + if(i>=a){ + System.out.println(i); + break; + } + b++; + } + } +} +``` + +## 88번 +```java +import java.util.*; + +class Main { + public static void main(String args[]) { + Scanner sc = new Scanner(System.in); + int a = sc.nextInt(); + int b=1; + while(true){ + if(b%3==0){ + } + else{ + System.out.printf("%d ",b); + } + if(a<=b){ + break; + } + b++; + } + } +} +``` + + From 0c5f5de7eb9be88d8ccb6ef0b664f33a46f118b9 Mon Sep 17 00:00:00 2001 From: beombu Date: Mon, 31 Jan 2022 01:32:29 +0900 Subject: [PATCH 6/8] add : leetcode_num3 --- 01/beom/leetcodeString.md | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 01/beom/leetcodeString.md diff --git a/01/beom/leetcodeString.md b/01/beom/leetcodeString.md new file mode 100644 index 00000000..724d2a0e --- /dev/null +++ b/01/beom/leetcodeString.md @@ -0,0 +1,53 @@ +# 문자열 문제 모음 + +## 목차 +## 3. Longest Substring Without Repeating Characters +## 763. Partition Labels +## 139. Word Break + + + + +## 3. Longest Substring Without Repeating Characters + +### 풀이 서술 +1. 문자열 s를 한 글자씩 배열에 넣는다. +2. for문을 통해 앞에 배열에 동일한 값이 나오면 break +3. 하위 문자열을 잘모르겠다. 아스키 코드를 사용하는 건가? + + +### 코드 +```java +import java.util.Scanner; + +class Solution { + public static int lengthOfLongestSubstring(String s) { + int len = s.length(); + int res = 0; + + for(int i=0;i Date: Mon, 31 Jan 2022 16:11:50 +0900 Subject: [PATCH 7/8] add leetcode 1672 --- 01/beom/leetcodeString.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/01/beom/leetcodeString.md b/01/beom/leetcodeString.md index 724d2a0e..e02befa1 100644 --- a/01/beom/leetcodeString.md +++ b/01/beom/leetcodeString.md @@ -1,11 +1,47 @@ # 문자열 문제 모음 ## 목차 +## 1672. Richest Customer Wealth ## 3. Longest Substring Without Repeating Characters ## 763. Partition Labels ## 139. Word Break +## 1672. Richest Customer Wealth +### 풀이서술 +1. 2차원 배열을 입력받고 +2. 2차원 배열의 for문 안에 sum을 구해 변수에 넣고 Math.max로 비교 +3. 가장 큰값 출력 + +### 코드 +```java +class Solution { + public static int maximumWealth(int[][] accounts) { + int res = 0; + int m = accounts.length; + int n = accounts[0].length; + + for(int i=0; i Date: Mon, 31 Jan 2022 17:51:29 +0900 Subject: [PATCH 8/8] add leetcode 20 --- 01/beom/leetcodeString.md | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/01/beom/leetcodeString.md b/01/beom/leetcodeString.md index e02befa1..788d3c97 100644 --- a/01/beom/leetcodeString.md +++ b/01/beom/leetcodeString.md @@ -2,6 +2,7 @@ ## 목차 ## 1672. Richest Customer Wealth +## 20. Valid Parentheses ## 3. Longest Substring Without Repeating Characters ## 763. Partition Labels ## 139. Word Break @@ -40,8 +41,56 @@ class Solution { } ``` +## 20. Valid Parentheses +### 풀이 서술 +1. 문자열을 입력받고 +2. 스택 자료구조를 사용 +3. ([{ 으로 시작하면 push +4. 아니면 )}]인 경우이므로 stack의 가장 위에 값이 맞는 괄호라면 pop +### 코드 +```java +import java.util.Stack; + +class Solution { + public static boolean isValid(String s) { + Stack stack = new Stack<>(); + for(int i=0;i