25083번
public class Main {
public static void main(String[] args) {
System.out.println(" ,r\'\"7");
System.out.println("r`-_ ,\' ,/");
System.out.println(" \\. \". L_r\'");
System.out.println(" `~\\/");
System.out.println(" |");
System.out.println(" |");
}
}
\ = \\
' = \'
" = \"
3003번
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(bf.readLine());
int[] arr = new int[6];
for(int i = 0; i<arr.length; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
arr[0] = 1 - arr[0];
arr[1] = 1 - arr[1];
arr[2] = 2 - arr[2];
arr[3] = 2 - arr[3];
arr[4] = 2 - arr[4];
arr[5] = 8 - arr[5];
for (int num : arr) {
System.out.print(num + " ");
}
}
}
2444번
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int num = Integer.parseInt(bf.readLine());
for(int i = 1; i <= num ; i++) {
for(int j = 0; j < num-i; j++)
System.out.print(" ");
for(int j = 0; j < i*2-1; j++)
System.out.print("*");
System.out.println();
}
for(int i = num-1; i >= 0 ; i--) {
for(int j = 0; j < num-i; j++)
System.out.print(" ");
for(int j = 0; j < i*2-1; j++)
System.out.print("*");
System.out.println();
}
}
}
for문 돌릴때 반복수세팅을 가운데 조건에서 맞춰버린다.
나중에 if로 풀어보자
10812번
import java.io.*;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bfw = new BufferedWriter(new OutputStreamWriter(System.out));
String str = bfr.readLine();
StringTokenizer st = new StringTokenizer(str, " ");
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int basket[] = new int[N + 1];
int newBasket[] = new int[N + 1];
for (int s = 1; s <= N; s++) {
basket[s] = s;
newBasket[s] = s;
}
String method;
StringTokenizer stt;
int i, j, k;
for (int s = 0; s < M; s++) {
method = bfr.readLine();
stt = new StringTokenizer(method);
i = Integer.parseInt(stt.nextToken());
j = Integer.parseInt(stt.nextToken());
k = Integer.parseInt(stt.nextToken());
int ii = i;
for (int g = 0; g < j - i + 1; g++) {
if (k + g <= j) {
newBasket[g + i] = basket[k + g];
} else {
newBasket[g + i] = basket[ii];
ii++;
}
}
for (int g = 1; g <= N; g++) {
basket[g] = newBasket[g];
}
}
for (int s = 1; s <= N; s++) {
bfw.write(newBasket[s] + " ");
}
bfr.close();
bfw.flush();
bfw.close();
}
}
10988번
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String str = bf.readLine();
StringBuilder sb = new StringBuilder(str);
if (str.equals(sb.reverse().toString())) {
System.out.println("1");
} else {
System.out.println("0");
}
}
}
문자열을 비교할때는 .equals()를 사용하자
== 은 가리키는 주소 같은지 판단하지만 .equals() 저장된 값이 같은지 비교해준다.
부정문일 경우 맨앞에 !붙여준다.
다음에 if로 풀어보기
4344번
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int cnt = Integer.parseInt(bf.readLine());
for (int i = 0; i<cnt; i++) {
st = new StringTokenizer(bf.readLine());
int std = Integer.parseInt(st.nextToken());
int sum = 0;
int[] arr = new int[std];
for (int j = 0; j<std; j++) {
arr[j] = Integer.parseInt(st.nextToken());
sum += arr[j];
}
double rv = sum/std;
int gs = 0;
for (int n : arr) {
if (rv < n) {
gs++;
}
}
double pst = (double) gs / (double) std * 100;
System.out.println(String.format("%.3f%%", pst));
}
}
}
퍼센트 계산하려면 double로 도배를 해야함... double pst = (double) gs / (double) std * 100;
소수점 셋째자리에서 반올림 후 출력 String.format("%.3f%%", pst)
% 출력하려면 ""마지막 부분에 %% 하면 됨
String.format()
printf
2941번
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String text = bf.readLine();
int num = text.length();
for (int i = 1; i< text.length(); i++) {
if (text.charAt(i) == '=') {
if (text.charAt(i-1) == 'c') {
num--;
} else if (text.charAt(i-1) == 's') {
num--;
} else if (text.charAt(i-1) == 'z') {
num--;
if (i>1) {
if (text.charAt(i-2) == 'd') {
num--;
}
}
}
}
if (text.charAt(i) == '-') {
if (text.charAt(i-1) == 'c') {
num--;
} else if (text.charAt(i-1) == 'd') {
num--;
}
}
if (text.charAt(i) == 'j') {
if (text.charAt(i-1) == 'l') {
num--;
} else if (text.charAt(i-1) == 'n') {
num--;
}
}
}
System.out.println(num);
}
}
ArrayIndexOutOfBoundsException 인덱스설정시 주의하자 없는 부분을 가리키지 않도록
25206번
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
double sum = 0;
double allSum = 0;
for (int i = 0; i<20; i++) {
st = new StringTokenizer(bf.readLine());
String sub = st.nextToken();
double score = Double.parseDouble(st.nextToken());
String rank = st.nextToken();
double Z = 0;
switch(rank) {
case "A+": Z = 4.5;
break;
case "A0": Z = 4.0;
break;
case "B+": Z = 3.5;
break;
case "B0": Z = 3.0;
break;
case "C+": Z = 2.5;
break;
case "C0": Z = 2.0;
break;
case "D+": Z = 1.5;
break;
case "D0": Z = 1.0;
break;
case "F": Z = 0.0;
break;
case "P": Z = 0.0;
score = 0.0;
break;
}
allSum += score * Z;
sum += score;
}
System.out.println(allSum / sum);
}
}
1316번
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException{
int count = 0;
int N = Integer.parseInt(br.readLine());
for (int i = 0; i < N; i++) {
if (check() == true) {
count++;
}
}
System.out.println(count);
}
public static boolean check() throws IOException {
boolean[] check = new boolean[26];
int prev = 0;
String str = br.readLine();
for(int i = 0; i < str.length(); i++) {
int now = str.charAt(i);
if (prev != now) {
if ( check[now - 'a'] == false ) {
check[now - 'a'] = true;
prev = now;
}
else {
return false;
}
}
else {
continue;
}
}
return true;
}
}