20230523
2023. 5. 23. 04:08ㆍTIL
백준 1110번
import java.util.*;
interface Main {
static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N=sc.nextInt();
int a=0,b=0,c=0,d=0,N_1=N,count=0;
while(true)
{
if(N<10)
{
c=N;
b=N;
}
else
{
a=N/10;
b=N-a*10;
if(a+b>=10)
{
c=a+b-10;
}
else
{
c=a+b;
}
}
N=b*10+c;
count++;
if(N_1==N)
break;
}
System.out.println(count);
}
}
interface Main {
static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N=sc.nextInt();
int a=0,b=0,c=0,d=0,N_1=N,count=0;
while(true)
{
if(N<10)
{
c=N;
b=N;
}
else
{
a=N/10;
b=N-a*10;
if(a+b>=10)
{
c=a+b-10;
}
else
{
c=a+b;
}
}
N=b*10+c;
count++;
if(N_1==N)
break;
}
System.out.println(count);
}
}
문제 후기 : 기본적으로 예외처리만 잘하면 쉽게 풀 수 있었던 문제였던거 같다
N=5일때 0+5 = 5 여기서 55가 되게 하면 된다 이게 5가 될때까지 반복하면 된다 그 반복 횟수를 출력하면 되기 때문에 반복 할 때마다 1을 증가할 수 있도록하면 되고 N의10이상의 값일 때는 합한 값의 예외 처리를 잘해주면 된다고 생각한다
오늘 팀원에게 while문에서 while(true)로 해서 무한히 돌릴 수 있는 이 방법을 듣지 못했다면 풀지못했을 거다
백준 1002번 터렛
import java.util.*;
interface Main {
static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T=sc.nextInt();
for(int i=0;i<T;i++) {
int x_1 = sc.nextInt();
int y_1 = sc.nextInt();
int r_1 = sc.nextInt();
int x_2 = sc.nextInt();
int y_2 = sc.nextInt();
int r_2 = sc.nextInt();
double tmp = Math.sqrt(Math.pow(x_1 - x_2, 2) + Math.pow(y_1 - y_2, 2));
if ((x_1 == x_2) && (y_1 == y_2)) {
if (r_1 == r_2) {
System.out.println(-1);
}
else {
System.out.println(0);
}
} else if (tmp==r_1+r_2)
{
System.out.println(1);
}
else if (tmp > r_1 + r_2)
{
System.out.println(0);
}
else if (tmp < r_1 + r_2)
{
if(Math.abs(r_1-r_2)==tmp){
System.out.println(1);
}
else if(Math.abs(r_1-r_2)>tmp){
System.out.println(0);
}
else
{
System.out.println(2);
}
}
}
}
}
interface Main {
static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T=sc.nextInt();
for(int i=0;i<T;i++) {
int x_1 = sc.nextInt();
int y_1 = sc.nextInt();
int r_1 = sc.nextInt();
int x_2 = sc.nextInt();
int y_2 = sc.nextInt();
int r_2 = sc.nextInt();
double tmp = Math.sqrt(Math.pow(x_1 - x_2, 2) + Math.pow(y_1 - y_2, 2));
if ((x_1 == x_2) && (y_1 == y_2)) {
if (r_1 == r_2) {
System.out.println(-1);
}
else {
System.out.println(0);
}
} else if (tmp==r_1+r_2)
{
System.out.println(1);
}
else if (tmp > r_1 + r_2)
{
System.out.println(0);
}
else if (tmp < r_1 + r_2)
{
if(Math.abs(r_1-r_2)==tmp){
System.out.println(1);
}
else if(Math.abs(r_1-r_2)>tmp){
System.out.println(0);
}
else
{
System.out.println(2);
}
}
}
}
}
문제 후기 : 원을 생각하고 하면 쉽게되겠다고 생각했다 그치만 생각보다 오래걸렸다 내가 생각한것 이외에도 다른 경우도 몇가지 있어서 그 경우 반영해서 코드를 작성하니 쉽게 풀 수 있었던 것 같다
같은 조 팀원에게 위의 사진 힌트를 받아서 풀었다 생각보다 쉬웠던 것 같다