1 | 1712 | ์์ต๋ถ๊ธฐ์ |
์ฒ์์๋ ์๋์ ๊ฐ์ด ์์ฑํ์ฌ ์๊ฐ์ด๊ณผ๊ฐ ์ผ์ด๋ฌ๋ค.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
long A = scan.nextInt();
long B = scan.nextInt();
long C = scan.nextInt();
scan.close();
long count = 1;
while(true) {
if(B>=C) {
System.out.println(-1);
break;}
if(A + B*count >= C*count) {
count++;
continue;
}
if(A + B*count < C*count) {
System.out.println(count);
break;
}
}
}
}
๊ทธ๋์ Scanner์ ๋นผ๊ณ BufferReadered๋ฅผ ์ฌ์ฉํ์ฌ ๋ค์ ์์ฑํ์๋๋ฐ๋ ์๊ฐ์ด๊ณผ๊ฐ ๋ฌ๋ค.
import java.io.*;
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 x = bfr.readLine();
String[] a = x.split(" ");
long A = Long.parseLong(a[0]);
long B = Long.parseLong(a[1]);
long C = Long.parseLong(a[2]);
int count = 1;
while(true) {
if(B>=C) {
bfw.write("-1");
bfw.flush();
break;}
if(A + B*count >= C*count) {
count++;
continue;
}
if(A + B*count < C*count) {
bfw.write(String.valueOf(count));
bfw.flush();
break;
}
}
bfr.close();
}
}
๋ค์ ์๊ฐํด ๋ณด๋
์ด๋ ๊ฒ ๊ฒฐ๊ณผ๊ฐ ๋์์ ์๋์ ์งง์ ์ฝ๋๋ก ์์ฑํ์๋ค.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
long A = scan.nextInt();
long B = scan.nextInt();
long C = scan.nextInt();
scan.close();
if(B>=C) System.out.println(-1);
else System.out.println(A/(C-B)+1);
}
}
2 | 2292 | ๋ฒ์ง |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan =new Scanner(System.in);
long T = scan.nextLong(); scan.close();
int x = 1; int count = 1;
while(true) {
if(T==x) break;
else if( x+1 <= T && T <= x + 6*count ) {
count++;
break;
}
else {
x += 6*count;
count++;
}
}
System.out.println(count);
}
}
3 | 1193 | ๋ถ์์ฐพ๊ธฐ |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int X = scan.nextInt();
scan.close();
int sum = 0;
int i= 0;
while(true) {
if(sum+1<= X && X <= sum+i) {
if(i%2==0) {
int count = X - sum;
System.out.println(count + "/" + (i+1-count));
break;
}
else {
int count = X - sum;
System.out.println((i+1-count) + "/" + count );
break;
}
}
else {
sum += i;
i++;
}
}
}
}
4 | 2869 | ๋ฌํฝ์ด๋ ์ฌ๋ผ๊ฐ๊ณ ์ถ๋ค |
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 stz = new StringTokenizer(bfr.readLine()," ");
int A = Integer.parseInt(stz.nextToken());
int B = Integer.parseInt(stz.nextToken());
int V = Integer.parseInt(stz.nextToken());
int day = (V-B) / (A-B);
if((V-B) % (A-B) != 0)
day ++;
System.out.println(day);
// int count = 1;
// int sum = 0;
// while(true) {
// sum+=A;
// if(sum >= V) {
// break;
// }
// sum -= B;
// count++;
// }
//
// System.out.println(count);
}
}
5 | 10250 | ACM ํธํ |
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));
int T = Integer.parseInt(bfr.readLine()); //test ์ผ์ด์ค
for(int i = 0; i<T; i++) {
StringTokenizer stz = new StringTokenizer(bfr.readLine(), " ");
int H = Integer.parseInt(stz.nextToken());//๋์ด
Integer.parseInt(stz.nextToken());//๊ธธ์ด
int N = Integer.parseInt(stz.nextToken()); //์ฌ๋์
if(N % H == 0) {
System.out.println(H*100+N/H);
}
else {
System.out.println((N%H)*100 + N/H + 1);
}
}
}
}
6 | 2775 | ๋ถ๋ ํ์ฅ์ด ๋ ํ ์ผ |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
for(int t=0; t<T; t++) {
int k = scan.nextInt();
int n = scan.nextInt();
int ary[][] = new int[k+1][n+1];
for(int i=0; i<=k; i++)
ary[i][0] = 1;
for(int i=0; i<=n; i++)
ary[0][i] = i+1;
for(int i=1; i<k+1; i++) {
for(int j=1; j<n+1; j++) {
ary[i][j] = ary[i][j-1] + ary[i-1][j];
}
}
System.out.println(ary[k][n-1]);
}
scan.close();
}
}
7 | 2839 | ์คํ ๋ฐฐ๋ฌ |
์ฒ์์๋ ์๋์ ๊ฐ์ด ํ์๋๋ฐ ์์ ์ ๋ ฅ๊ณผ ์ถ๋ ฅ์ ์ ์๋ํ๊ณ ๋ด ์๊ฐ์๋ ์๋๋๊ฑฐ ๊ฐ์๋ฐ ์ ๋ง ๋ต์ด ์๋์์ ๋ค์ ์๊ฐํ์๋ค.
package ๋ฐฑ์ค;
import java.util.Scanner;
public class no2893 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
scan.close();
int five = N/5;
int three = (N%5)/3;
if(five*5 + three*3 != N) {
int count= 0;
if(N%3==0) System.out.println(N/3);
else {
while(true) {
if(N %3 != 0) {
N -= 5;
count++;
if(N<=0) {
System.out.println(-1);
break;
}
}
else {
System.out.println(N/3 + count);
break;
}
}
}
}
else
System.out.println(five + three);
}
}
//if((N%5)%3 != 0 ) {
// if(N>4 &&(N%5+5)%3 == 0) {
// five = N/5-1;
// three = (N%5+5)/3;
// }
// else if(N%3 != 0) {
// five = 0;
// three = -1;
// }
// else {
// five = 0;
// three = N/3;
// }
//}
//
์์ ํ ์ฝ๋๋ฅผ ๋ฐ๊ฟ์ ์๋์ ๊ฐ์ด ํ์๋ค. 5๋ก ๊ณ์ ๋๋ ๋ณด๊ณ ์๋๋ฉด 3์ฉ ๋นผ๊ณ 3์ ์นด์ดํธํ์๋ค.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
scan.close();
int three = 0;
while (true) {
if (n % 5 == 0) {
System.out.println((n / 5) + three);
break;
}
else if (n <= 0) {
System.out.println(-1);
break;
}
else {
n = n - 3;
three++;
}
}
}
}
8 | 10757 | ํฐ ์ A+B |
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
BigInteger A = scan.nextBigInteger();
BigInteger B = scan.nextBigInteger();
System.out.println(A.add(B));
scan.close();
}
}
9 | 1011 | Fly me to the Alpha Centauri |
์ด ๋ฌธ์ ๋ ๊ท์น์ ์ฐพ๋๋ผ ์ค๋ ๊ฑธ๋ ธ๋ค.
๊ฒฐ๊ตญ ์๋์ ๊ฐ์ด ๋ด๊ฐ ์๊ฐํ์ ๋์ ์ต์ ์ ํจ์จ์ฑ์ ๊ฐ์ง ๊ท์น์ ๋ฐ๊ฒฌํ์๋ค.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
for(int i=0; i<T; i++) {
long X = scan.nextLong();
long Y = scan.nextLong();
long count = 1;
long distance = 0;
while(Y-X > distance) {
count++;
distance += count/2;
}
System.out.println(count -1);
}
scan.close();
}
}
๋ง์ ์ฝ๋๋ฅผ ์จ๋ณด๋ ์๊ฐ๋๋น ์ฝ๋๊ฐ ๋๋ฌด ๊ฐ๋จํด๋ณด์ฌ์ ์ฑ์ทจ๊ฐ์ด ๊ฐ์๋์๋ค.