package com.backjun.algorithm;

import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int hambergLowPrice=0;
		int beverageLowPrice=0;

		for (int i=0; i<5; i++){
			int price = Integer.parseInt(br.readLine());
			if(i==0){
				hambergLowPrice = price;
			} else if (i<3) {
				hambergLowPrice = price < hambergLowPrice ? price : hambergLowPrice;
			} else if (i==3) {
				beverageLowPrice = price;
			} else if (i<5) {
				beverageLowPrice = price < beverageLowPrice ? price : beverageLowPrice;
			}

		}
		System.out.println(hambergLowPrice + beverageLowPrice - 50);
	}
}

Math.min을 사용하면 아래처럼.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	static int min(int a, int b){
		return a<b ? a:b;
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		System.out.print(min(Integer.parseInt(br.readLine()), min(Integer.parseInt(br.readLine()),
				Integer.parseInt(br.readLine()))) + min(Integer.parseInt(br.readLine()),
				Integer.parseInt(br.readLine())) - 50);
	}
}

min을 함수로 정의해서 사용.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	static int min(int a, int b){
		return a<b ? a:b;
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		System.out.print(min(Integer.parseInt(br.readLine()), min(Integer.parseInt(br.readLine()),
				Integer.parseInt(br.readLine()))) + min(Integer.parseInt(br.readLine()),
				Integer.parseInt(br.readLine())) - 50);
	}
}

'알고리즘 > acmicpc.net' 카테고리의 다른 글

#10039  (0) 2020.07.13
1110  (0) 2020.07.10
10951&10952  (0) 2020.07.10
10871  (0) 2020.07.08
2439  (0) 2020.07.08
package com.backjun.algorithm;

import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

		ArrayList<Integer> arr = new ArrayList();
		String line;
		int cnt =0;
		while (true){
			line = br.readLine();
			int score = Integer.parseInt(line);
			if(score >= 40){
				arr.add(score);
			} else {
				arr.add(40);
			}
			cnt++;
			if(cnt==5){
				break;
			}
		}
		int result = (int)arr.stream().mapToInt(Integer::intValue).average().getAsDouble();
		System.out.println(result);

//		bw.flush();
//		bw.close();

	}
}

'알고리즘 > acmicpc.net' 카테고리의 다른 글

#5543  (0) 2020.07.13
1110  (0) 2020.07.10
10951&10952  (0) 2020.07.10
10871  (0) 2020.07.08
2439  (0) 2020.07.08
import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int input = Integer.parseInt(br.readLine());
		int a = input/10;
		int b = input%10;
		int cnt = 0;
		int result;
		while (true){
			cnt++;
			result = (b*10) + (a+b)%10;
			a = result/10;
			b = result%10;
			//System.out.println("Step" + cnt + ": " + result + " a: " + a + ", b: " + b);
			if(result == input){
				break;
			}
		}

		System.out.println(cnt);
	}
}

다른 사람꺼 퍼옴

import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();
         
        int number = n;
        int count = 0;
         
        do {
            number = number % 10 * 10 + (number / 10 + number % 10) % 10;
            count++;
        } while (n != number);
         
        System.out.println(count);
    }
}

'알고리즘 > acmicpc.net' 카테고리의 다른 글

#5543  (0) 2020.07.13
#10039  (0) 2020.07.13
10951&10952  (0) 2020.07.10
10871  (0) 2020.07.08
2439  (0) 2020.07.08

#10951

import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int a,b;
		String line;
		while((line=br.readLine())!=null) {
			StringTokenizer st = new StringTokenizer(line);
			a = Integer.parseInt(st.nextToken());
			b = Integer.parseInt(st.nextToken());
			System.out.println(a+b);
		}

	}
}

#10952

import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		int a,b;
		StringTokenizer st = new StringTokenizer(br.readLine());
		a = Integer.parseInt(st.nextToken());
		b = Integer.parseInt(st.nextToken());
		System.out.println(a+b);
		while ((a+b)!=0){
			st = new StringTokenizer(br.readLine());
			a = Integer.parseInt(st.nextToken());
			b = Integer.parseInt(st.nextToken());
			if ((a+b)!=0){
				System.out.println(a+b);
			}
		}
		bw.flush();
		bw.close();
	}
}

위 를 좀더 정리...

import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		int a,b;

		while(true) {
			StringTokenizer st = new StringTokenizer(br.readLine());
			a = Integer.parseInt(st.nextToken());
			b = Integer.parseInt(st.nextToken());
			if ((a+b)==0){
				break;
			}
			System.out.println(a+b);
		}
		bw.flush();
		bw.close();

	}
}

'알고리즘 > acmicpc.net' 카테고리의 다른 글

#10039  (0) 2020.07.13
1110  (0) 2020.07.10
10871  (0) 2020.07.08
2439  (0) 2020.07.08
11022  (0) 2020.07.08
import java.io.*;
import java.util.*;

public class Main {
	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 line1 = br.readLine();
		String line2 = br.readLine();
		int N = Integer.parseInt(line1.split(" ")[0]);
		int X = Integer.parseInt(line1.split(" ")[1]);
		String[] arr = line2.split(" ");
		int target;
		for (int i=0; i<N; i++){
			target = Integer.parseInt(arr[i]);
			if (target < X){
				bw.write(target + " ");
			}
		}
		
		bw.flush();//남아있는 데이터를 모두 출력시킴
		bw.close();//스트림을 닫음
	}
}

'알고리즘 > acmicpc.net' 카테고리의 다른 글

1110  (0) 2020.07.10
10951&10952  (0) 2020.07.10
2439  (0) 2020.07.08
11022  (0) 2020.07.08
11021.  (0) 2020.07.08

별 순차

import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

		int cnt = Integer.parseInt(br.readLine());
		for(int i=1; i<=cnt; i++){
			for(int j=1; j<=i; j++){
				bw.write("*");
			}
			bw.write("\n");
		}
		bw.flush();//남아있는 데이터를 모두 출력시킴
		bw.close();//스트림을 닫음
	}
}

별 우측정렬

import java.io.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

		int cnt = Integer.parseInt(br.readLine());

		for(int i=0; i<cnt; i++){
			for(int j=1; j<(cnt-i); j++){
				bw.write(" ");
			}
			for(int j=0; j<=i; j++) {
				bw.write("*");
			}
			bw.newLine();
		}
		bw.flush();//남아있는 데이터를 모두 출력시킴
		bw.close();//스트림을 닫음
	}
}

'알고리즘 > acmicpc.net' 카테고리의 다른 글

10951&10952  (0) 2020.07.10
10871  (0) 2020.07.08
11022  (0) 2020.07.08
11021.  (0) 2020.07.08
2741. N찍 & 2742.N반대로찍  (0) 2020.07.08

+ Recent posts