import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Stack<Double> stack = new Stack<>();
int n = sc.nextInt();
sc.nextLine();
double arr[] = new double[n];
String str = sc.nextLine();
for(int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
for(char c : str.toCharArray()) {
if(c >= 'A' && c <= 'Z') {
stack.push(arr[c - 'A']);
} else if(c == '*') {
double a = stack.pop();
double b = stack.pop();
stack.push(a * b);
} else if(c == '+') {
double a = stack.pop();
double b = stack.pop();
stack.push(a + b);
} else if(c == '-') {
double a = stack.pop();
double b = stack.pop();
stack.push(b - a);
} else if(c == '/') {
double a = stack.pop();
double b = stack.pop();
stack.push(b / a);
}
}
double answer = stack.pop();
System.out.print(String.format("%.2f", answer));
sc.close();
}
}
import java.io.*;
import java.util.Stack;
public class Main {
static StringBuilder sb = new StringBuilder();
static int priority(char c) {
if(c == '(') {
return 0;
}
if(c == '+' || c == '-') {
return 1;
}
return 2;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String str = br.readLine();
Stack<Character> stack = new Stack<>();
for(char c : str.toCharArray()) {
if(c >= 'A' && c <= 'Z') {
sb.append(c);
} else if(c == '(') {
stack.push(c);
} else if(c == ')') {
while(!stack.isEmpty()) {
if(stack.peek() == '(') {
stack.pop();
break;
}
sb.append(stack.pop());
}
} else { // 연산자일 경우
while(!stack.isEmpty() && priority(stack.peek()) >= priority(c)) {
sb.append(stack.pop());
}
stack.push(c);
}
}
while(!stack.isEmpty()) {
sb.append(stack.pop());
}
bw.write(sb.toString());
bw.close();
br.close();
}
}
Scanner로 하려는데 계속 틀렸다고 떠서.. BufferedReader 썼더니 정답처리됨
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
int arr[] = new int[26];
for(char c : str.toCharArray()) {
arr[(int)c - 'a']++;
}
for(int i : arr) {
System.out.print(i + " ");
}
sc.close();
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = new int[26];
for(int i = 0; i < arr.length; i++) {
arr[i] = -1;
}
String str = sc.next();
for(int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if(arr[c - 'a'] == -1) {
arr[c - 'a'] = i;
}
}
for(int a : arr) {
System.out.print(a + " ");
}
sc.close();
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
String str = sc.nextLine();
int sm = 0; // 소문자
int bg = 0; // 대문자
int d = 0; // 숫자
int b = 0; // 공백
for(char c : str.toCharArray()) {
if(c == ' ') {
b++;
} else if(Character.isDigit(c)) {
d++;
} else {
if(Character.isUpperCase(c)) {
bg++;
} else {
sm++;
}
}
}
System.out.println(sm + " " + bg + " " + d + " " + b);
}
sc.close();
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
System.out.println(str.length());
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
for(char c : str.toCharArray()) {
if(c >= 'A' && c <= 'Z') { // A ~ Z : 65 ~ 90
c += 13;
if(c > 'Z') {
c -= 26;
}
} else if(c >= 'a' && c <= 'z') { // a ~ z : 97 ~ 122
c += 13;
if(c > 'z') {
c -= 26;
}
}
System.out.print(c);
}
sc.close();
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long a = sc.nextInt(); long b = sc.nextInt();
long c = sc.nextInt(); long d = sc.nextInt();
long answer = (long) (a * Math.pow(10, String.valueOf(b).length()) + b + (c * Math.pow(10, String.valueOf(d).length())) + d);
System.out.println(answer);
sc.close();
}
}
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
String arr[] = new String[str.length()];
for(int i = 0; i < arr.length; i++) {
arr[i] = str.substring(i); // i 번째부터 문자열 가져옴
}
Arrays.sort(arr); // 사전순으로 정렬
for(String s : arr) {
System.out.println(s);
}
sc.close();
}
}