https://www.acmicpc.net/problem/3986
3986번: 좋은 단어
이번 계절학기에 심리학 개론을 수강 중인 평석이는 오늘 자정까지 보고서를 제출해야 한다. 보고서 작성이 너무 지루했던 평석이는 노트북에 엎드려서 꾸벅꾸벅 졸다가 제출 마감 1시간 전에
www.acmicpc.net
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
int answer = 0;
Scanner input = new Scanner(System.in);
int n = input.nextInt();
String[] words = new String[n];
for(int i = 0; i < n; i++) {
words[i] = input.next();
}
for(String word : words) {
Stack<Character> stack = new Stack<>();
check(stack, word);
if(stack.isEmpty()) answer++;
}
System.out.println(answer);
}
// stack과 비교하는 메서드
private static void check(Stack<Character> stack, String word) {
stack.push(word.charAt(0)); // 첫 번째 문자는 바로 stack에 추가시킨다.
/* 2번째 문자부터 스택이 비어있지 않는 선에서 반복을 돌며 pop과 push를 반복*/
for(int i = 1; i < word.length(); i++) {
if(!stack.isEmpty() && stack.peek() == word.charAt(i)){
stack.pop();
continue;
}
stack.push(word.charAt(i));
}
}
}
https://www.acmicpc.net/problem/1935
1935번: 후위 표기식2
첫째 줄에 피연산자의 개수(1 ≤ N ≤ 26) 가 주어진다. 그리고 둘째 줄에는 후위 표기식이 주어진다. (여기서 피연산자는 A~Z의 영대문자이며, A부터 순서대로 N개의 영대문자만이 사용되며, 길이
www.acmicpc.net
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[] arr = new int[N];
Stack<Double>s = new Stack<Double>();
String str = br.readLine();
for(int i = 0; i< N; i++) {
arr[i] = Integer.parseInt(br.readLine());
}
for(int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if(c >= 'A' && c <= 'Z') {
s.push((double)arr[c-'A']);
}
else {
double num2 = s.pop();
double num1 = s.pop();
switch(c) {
case '+':
s.push(num1 + num2);
break;
case '-':
s.push(num1 - num2);
break;
case '*':
s.push(num1 * num2);
break;
case '/':
s.push(num1 / num2);
break;
}
}
}
System.out.printf("%.2f",s.pop());
}
}

느낀점 SQL 공부를 하는데 책의 초반부터 막혀서 힘들었다. SQL을 설치 한 후 데이터베이스 사용자를 생성하기 위해 권한을 부여해야하는데 그 과정이 불가능했다. 머리가 아프길래 일단 2단원 먼저 시작하게 되었다.
'2022여름방학_모각코' 카테고리의 다른 글
진저비어 팀: 모각코 3주차 모임 활동결과(22.07.27 / 수요일 / 14:00~17:00) (0) | 2022.07.27 |
---|---|
진저비어 팀: 모각코 3주차 모임 목표(22.07.27 / 수요일 / 14:00~17:00) (0) | 2022.07.27 |
진저비어 팀: 모각코 2주차 모임 목표(22.07.13 / 수요일 / 14:00~17:00) (0) | 2022.07.13 |
진저비어 팀: 모각코 1주차 모임 활동결과(22.07.06 / 수요일 / 14:00~17:00) (0) | 2022.07.06 |
진저비어 팀: 모각코 1주차 모임 목표(22.07.06 / 수요일 / 14:00~17:00) (0) | 2022.07.06 |
https://www.acmicpc.net/problem/3986
3986번: 좋은 단어
이번 계절학기에 심리학 개론을 수강 중인 평석이는 오늘 자정까지 보고서를 제출해야 한다. 보고서 작성이 너무 지루했던 평석이는 노트북에 엎드려서 꾸벅꾸벅 졸다가 제출 마감 1시간 전에
www.acmicpc.net
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
int answer = 0;
Scanner input = new Scanner(System.in);
int n = input.nextInt();
String[] words = new String[n];
for(int i = 0; i < n; i++) {
words[i] = input.next();
}
for(String word : words) {
Stack<Character> stack = new Stack<>();
check(stack, word);
if(stack.isEmpty()) answer++;
}
System.out.println(answer);
}
// stack과 비교하는 메서드
private static void check(Stack<Character> stack, String word) {
stack.push(word.charAt(0)); // 첫 번째 문자는 바로 stack에 추가시킨다.
/* 2번째 문자부터 스택이 비어있지 않는 선에서 반복을 돌며 pop과 push를 반복*/
for(int i = 1; i < word.length(); i++) {
if(!stack.isEmpty() && stack.peek() == word.charAt(i)){
stack.pop();
continue;
}
stack.push(word.charAt(i));
}
}
}
https://www.acmicpc.net/problem/1935
1935번: 후위 표기식2
첫째 줄에 피연산자의 개수(1 ≤ N ≤ 26) 가 주어진다. 그리고 둘째 줄에는 후위 표기식이 주어진다. (여기서 피연산자는 A~Z의 영대문자이며, A부터 순서대로 N개의 영대문자만이 사용되며, 길이
www.acmicpc.net
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[] arr = new int[N];
Stack<Double>s = new Stack<Double>();
String str = br.readLine();
for(int i = 0; i< N; i++) {
arr[i] = Integer.parseInt(br.readLine());
}
for(int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if(c >= 'A' && c <= 'Z') {
s.push((double)arr[c-'A']);
}
else {
double num2 = s.pop();
double num1 = s.pop();
switch(c) {
case '+':
s.push(num1 + num2);
break;
case '-':
s.push(num1 - num2);
break;
case '*':
s.push(num1 * num2);
break;
case '/':
s.push(num1 / num2);
break;
}
}
}
System.out.printf("%.2f",s.pop());
}
}

느낀점 SQL 공부를 하는데 책의 초반부터 막혀서 힘들었다. SQL을 설치 한 후 데이터베이스 사용자를 생성하기 위해 권한을 부여해야하는데 그 과정이 불가능했다. 머리가 아프길래 일단 2단원 먼저 시작하게 되었다.
'2022여름방학_모각코' 카테고리의 다른 글
진저비어 팀: 모각코 3주차 모임 활동결과(22.07.27 / 수요일 / 14:00~17:00) (0) | 2022.07.27 |
---|---|
진저비어 팀: 모각코 3주차 모임 목표(22.07.27 / 수요일 / 14:00~17:00) (0) | 2022.07.27 |
진저비어 팀: 모각코 2주차 모임 목표(22.07.13 / 수요일 / 14:00~17:00) (0) | 2022.07.13 |
진저비어 팀: 모각코 1주차 모임 활동결과(22.07.06 / 수요일 / 14:00~17:00) (0) | 2022.07.06 |
진저비어 팀: 모각코 1주차 모임 목표(22.07.06 / 수요일 / 14:00~17:00) (0) | 2022.07.06 |