1 | 11047 | ๋์ 0 |
๋์ ์ ์กฐ๊ฑด์ด ํน๋ณํด์ ๋์ ํ๋ก๊ทธ๋๋ฐ๋ณด๋ค ๋น ๋ฅด๊ฒ ๋ต์ ์ฐพ์ ์ ์๋ ๋ฌธ์ |
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));
StringTokenizer bd = new StringTokenizer(bfr.readLine());
int T = Integer.parseInt(bd.nextToken());
int money = Integer.parseInt(bd.nextToken());
int array[] = new int[T];
for(int i=0; i<T; i++) { //์ฌ์ฉ๋ ๋ ๋จ์ ์
๋ ฅ๋ฐ์
array[i] = Integer.parseInt(bfr.readLine());
}
int count = 0;
for(int i=array.length-1; i>=0; i--) {
if(money/array[i] > 0) {
count += money/array[i];
money %= array[i];
}
}
System.out.println(count);
}
}
T, money = map(int, input().split(' '))
array = []
for i in range(T) :
array.append(int(input()))
array.reverse()
count =0
for i in array:
if money // i > 0 :
count += money//i
money = money % i
print(count)
2 | 1931 | ํ์์ค ๋ฐฐ์ |
๊ฐ๋ฅํ ํ ๋ง์ ๊ตฌ๊ฐ์ ์ ํํ๋ ๋ฌธ์ |
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int[][] times = new int[n][2]; // 0 : start 1 : finish
int min = -1;
for(int i = 0; i < n; i++) {
times[i][0] = scan.nextInt();
times[i][1] = scan.nextInt();
}
Arrays.sort(times, (a,b) -> a[1] == b[1]? a[0] - b[0] : a[1] - b[1]);
int cnt = 0;
for(int i = 0; i < n; i++) {
if(times[i][0] >= min) {
min = times[i][1];
cnt++;
}
}
System.out.println(cnt);
}
}
3 | 11399 | ATM |
๊ธฐ๋ค๋ฆฌ๋ ์๊ฐ์ ํฉ์ ์ต์ํํ๋ ๋ฌธ์ |
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int array[] = new int[N];
for(int i=0; i<N; i++)
array[i] = scan.nextInt();
Arrays.sort(array);
int sum=0;
for(int i=0; i<N; i++) {
sum += array[i]*(N-i);
}
System.out.println(sum);
}
}
4 | 1541 | ์์ด๋ฒ๋ฆฐ ๊ดํธ |
์์ ๊ฐ์ ๊ฐ๋ฅํ ํ ์๊ฒ ๋ง๋๋ ๋ฌธ์ |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String a[] = scan.nextLine().split("\\-");
int sum= Integer.MAX_VALUE;
for(int i=0; i < a.length; i++) {
int temp =0;
String b[] = a[i].split("\\+");
for(int j=0; j<b.length; j++) {
temp += Integer.parseInt(b[j]);
}
if (sum== Integer.MAX_VALUE) {
sum = temp;
}
else sum -= temp;
}
System.out.println(sum);
}
}
5 | 13305 | ์ฃผ์ ์ |
์ต์ ๋น์ฉ์ผ๋ก ์ฃผ์ ํ์ฌ ์ผ์ง์ ๋๋ก๋ฅผ ๋ฌ๋ฆฌ๋ ๋ฌธ์ |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
//์
๋ ฅ๊ฐ ์
๋ ฅ๋ฐ๊ธฐ
int T = scan.nextInt();
long km[] = new long[T];
long city[] = new long[T];
for(int i=0; i<T-1; i++){
km[i] = scan.nextLong();
}
for(int i=0; i<T; i++)
city[i] = scan.nextLong();
long price = 0;
for(int i=0; i<T-1; i++) {
if(city[i] > city[i+1]) { //๋ค์๋ถ๋ถ์ด ํ์ฌ๋ถ๋ถ๋ณด๋ค ์ ๋ ดํ๊ฐ?
price += km[i]*city[i];//ํ์ฌ๊ฐ๊ฒฉ์ผ๋ก ์ต์๊ฑฐ๋ฆฌ ์ด๋. ๋ค์์ง์ญ์ผ๋ก
}
else {//ํ์ฌ ๋์๊ฐ ๋ค์์ง์ญ๋ณด๋ค ๋ ์ ๋ ดํ๋ ๋ค์์ง์ญ๊น์ง keep
city[i+1] = city[i];
price += km[i]*city[i]; //๋ง์ง๋ง๋์์ด๋ฉด ์ง๊ธ๊น์ง๊ฐ ์ ์ฅ.
}
}
System.out.println(price);
}
}
728x90
๋ฐ์ํ