Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1주차 Assignment - 한장수 #5

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions 1주차_과제/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
8 changes: 8 additions & 0 deletions 1주차_과제/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions 1주차_과제/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions 1주차_과제/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions 1주차_과제/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions 1주차_과제/1W_Homework.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
26 changes: 26 additions & 0 deletions 1주차_과제/src/BJ_10810/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package BJ_10810;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner scanner1 = new Scanner(System.in);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

더 빠른 입력을 위해 Scanner 대신 BufferedReader를 사용해보는 것도 추천드려요!

자세한 사용법은 링크 남겨둡니다: https://rlakuku-program.tistory.com/33

int basketNum = scanner1.nextInt(); // 바구니 개수
int repeatNum = scanner1.nextInt(); // 반복활 횟수
int[] basket = new int[basketNum + 1]; // basket[0 ~ basketNum]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 인덱스가 헷갈릴 때는 아예 배열의 크기를 +1로 잡아두고 시작하는 것도 방법입니다!

for (int a = 0; a < repeatNum; a++) // i번 바구니부터 j번 바구니까지 k번 공을 넣음
{
int i = scanner1.nextInt();
int j = scanner1.nextInt();
int k = scanner1.nextInt();

// 여기서부터 참조했음, https://www.acmicpc.net/board/view/128224
for(int b = i; b <= j; b++) // i : 최솟값(변화x), j : 최댓값(변화x) / b : 범위(변화O)
basket[b] = k;
}
for (int c = 1; c <= basketNum; c++)
System.out.printf("%d ", basket[c]);
}
}
Binary file added 1주차_과제/src/BJ_10810/백준_10810.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions 1주차_과제/src/BJ_11021/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package BJ_11021;

import java.util.Scanner;

public class Main
{
public static void main(String[] args)
{
Scanner scanner1 = new Scanner(System.in);
int T = scanner1.nextInt();
for (int i = 1; i <= T; i++)
{
int A = scanner1.nextInt();
int B = scanner1.nextInt();
System.out.printf("Case #" + i + ": %d\n", A + B);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

잘 푸셨습니다!
팁 하나를 드리자면 많은 양의 정보를 System.out.print()로 반복 호출하여 출력하는 것은 효율적이지 않을 수 있습니다. 이보다 StringBuilder를 사용해서 정답 문자열을 먼저 생성하고 마지막에 딱 한 번 System.out.print()를 호출하면 좋을 것 같습니다!

StringBuilder 사용법도 위 링크에 같이 있습니다..!

}
}
}
Binary file added 1주차_과제/src/BJ_11021/백준_11021.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions 1주차_과제/src/BJ_2439/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package BJ_2439;

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner scanner1 = new Scanner(System.in);
int repeatNum = scanner1.nextInt();

for(int i = 0; i < repeatNum; i++)
{
for (int j = repeatNum - 1; j > i; j--)
{
System.out.printf(" ");
}

for(int j = 0; j < i + 1; j++)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

약간 고려할 부분이 있는 문제인데 도움 없이 잘 푸셨네요!

{
System.out.printf("*");
}
System.out.printf("\n");
}
}
}
Binary file added 1주차_과제/src/BJ_2439/백준_2439.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions 1주차_과제/src/BJ_2588/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package BJ_2588;

import java.util.Scanner;

public class Main
{
public static void main(String[] args)
{
int input1, input2;
Scanner scanner1 = new Scanner(System.in);

input1 = scanner1.nextInt();
input2 = scanner1.nextInt();

System.out.printf("%d\n", input2 % 100 % 10 * input1);
System.out.printf("%d\n", input2 % 100 / 10 * input1);
System.out.printf("%d\n", input2 / 100 * input1);
System.out.printf("%d\n", input1 * input2);

/*
int number1, number2, B1, B2, B3; char C1, C2, C3; String input1, input2;
Scanner scanner1 = new Scanner(System.in);

input1 = scanner1.nextLine();
number1 = Integer.parseInt(input1);
input2 = scanner1.nextLine();

C1 = input2.charAt(0); B1 = Character.getNumericValue(C1);
C2 = input2.charAt(1); B2 = Character.getNumericValue(C2);
C3 = input2.charAt(2); B3 = Character.getNumericValue(C3);
number2 = Integer.parseInt(input2);

System.out.printf("%d\n", B3 * number1);
System.out.printf("%d\n", B2 * number1);
System.out.printf("%d\n", B1 * number1) ;
System.out.printf("%d\n",number1 * number2);
*/
}
}
Binary file added 1주차_과제/src/BJ_2588/백준_2588.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions 1주차_과제/src/BJ_2884/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package BJ_2884;

import java.util.Scanner;

public class Main
{
public static void main(String[] args)
{
Scanner scanner1 = new Scanner(System.in);
int H = scanner1.nextInt();
int M = scanner1.nextInt();

M = M - 45;
if (H == 0 && M < 0)
{
H = 23;
M = 60 + M;
}
else if (H != 0 && M < 0)
{
H--;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋은 아이디어와 분기 처리입니다! 총 3가지 경우로 나누셨군요

M = 60 + M;
}
System.out.printf("%d %d\n", H, M);
}
}
Binary file added 1주차_과제/src/BJ_2884/백준_2884.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions 1주차_과제/src/BJ_9086/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package BJ_9086;

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner scanner1 = new Scanner(System.in);

int repeatNum = scanner1.nextInt();
for(int i = 0; i < repeatNum; i++)
{
String input = scanner1.next();

char input1 = input.charAt(0);
char input2 = input.charAt(input.length() - 1);

System.out.printf("%c%c\n",input1, input2);
}
}
}
Binary file added 1주차_과제/src/BJ_9086/백준_9086.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions 1주차_과제/src/assignments/Test1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package assignments;

class Cylinder
{
public static final double PI = 3.14; // 원주율 3.14를 정적 상수 PI로 선언과 동시에 초기화

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 잘 수정하셨습니다!! 고생하셨어요~ 과제 통과입니다

int x, y; // 정수형 원의 중심 좌표 x, y를 선언
double r; // 실수형 원의 반지름 r을 선언
int height = 10; // 정수형 원기둥의 높이 변수 height을 10으로 선언과 동시에 초기화

// 생성자1: 정수 인자 x, y 와 실수 인자 r을 전달 받아서 해당 필드 값을 초기화
Cylinder(int x, int y, double r) { this.x = x; this.y = y; this.r = r; }
// 생성자2: 정수 인자 x, y, height 와 실수 인자 r을 전달 받아서 해당 필드 값을 초기화
Cylinder(int x, int y, double r, int height) { this.x = x; this.y = y; this.r = r; this.height = height; }

double circleArea() { return PI * Math.pow(r, 2); } // area 메서드: PI를 이용하여 원의 면적 반환
double volume() { return PI * Math.pow(r, 2) * height; } // volume 메서드: 면적과 높이를 이용하여 부피를 반환
double surfaceArea() { return 2 * PI * r * height + 2 * PI * Math.pow(r, 2); } // surfaceArea 메서드: PI를 이용하여 원기둥의 겉넓이를 반환

//move 메서드: 정수 인자 dx, dy를 전달 받아서 원의 중심 좌표를 이동 - 예: 필드 x가 1이고 dx가 10이면 x는 11로 변경되어야 함, 객체 자신을 반환함
Cylinder move(int dx, int dy)
{
x = dx + x; y = dy + y;
return this;
}
void print() { System.out.println("<"+x+","+y+":"+r+">");}
}
// 메인메서드 수행시 이렇게 출력되도록
//<13,15:6.0>
//113.04
//1130.4
//602.88
//<17,25:10.0>
//314.0
//1570.0
//942.0
public class Test1
{
public static void main(String[] args) {
Cylinder c1 = new Cylinder(3,5, 6);
c1.move(10,10).print();
System.out.println(c1.circleArea());
System.out.println(c1.volume());
System.out.println(c1.surfaceArea());

Cylinder c2 = new Cylinder(5,8, 10, 5);
c2.move(12,17).print();
System.out.println(c2.circleArea());
System.out.println(c2.volume());
System.out.println(c2.surfaceArea());
}
}