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

알고리즘 기초 정렬 문제 풀이 #20

Merged
merged 1 commit into from
Aug 17, 2018
Merged
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
74 changes: 74 additions & 0 deletions sort/Code_10814.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package sort;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/*
* �ۼ��� : 2018�� 08�� 16��
* �� �� : ���̼� ����
*/
public class Code_10814 {

public static void main(String[] args) throws NumberFormatException, IOException {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

List<Person> list = new ArrayList<Person>();

for(int i=0; i<n; ++i) {
String[] s = br.readLine().split(" ");
Person p = new Person();
p.age = Integer.parseInt(s[0]);
p.name = s[1];
p.join = i;
list.add(p);
}

Collections.sort(list);

for(Person p : list)
System.out.println(p);
}

}
//1.������ ������ person������ �ִ´� 2.stable sorting�� ����Ѵ�.
class Person implements Comparable<Person>{
int age;
String name;
int join;
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getJoin() {
return join;
}
public void setJoin(int join) {
this.join = join;
}

@Override
public String toString() {
return this.getAge()+" "+this.getName();
}

@Override
public int compareTo(Person p) {
int r = this.age-p.age;
if(r!=0) return r;
return this.join-p.join;
}
}
86 changes: 86 additions & 0 deletions sort/Code_10825.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package sort;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/*
* �ۼ��� : 2018�� 08�� 16��
* �� �� : ������
*/
public class Code_10825 {

public static void main(String[] args) throws NumberFormatException, IOException {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

List<Student> list = new ArrayList<Student>();

for(int i=0; i<n; ++i) {
String[] s = br.readLine().split(" ");
Student st = new Student();
String name = s[0];
int ko = Integer.parseInt(s[1]);
int eng = Integer.parseInt(s[2]);
int math = Integer.parseInt(s[3]);
st.ko = ko;
st.eng = eng;
st.math = math;
st.name = name;
list.add(st);
}

Collections.sort(list);

for(Student s : list)
System.out.println(s.getName());
}
}

class Student implements Comparable<Student>{
int ko;
int math;
int eng;
String name;
public int getKo() {
return ko;
}
public void setKo(int ko) {
this.ko = ko;
}
public int getMath() {
return math;
}
public void setMath(int math) {
this.math = math;
}
public int getEng() {
return eng;
}
public void setEng(int eng) {
this.eng = eng;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

@Override
public int compareTo(Student s) {
int r = s.ko - this.ko; //���������� �����ϴ� ��
if(r==0) {
r = this.eng - s.eng; //���������� �����ϴ� ��
if(r==0)
r = s.math - this.math; //���������� �����ϴ� ��
if(r==0)
r = this.name.compareTo(s.name);
}
return r;
}
}
30 changes: 30 additions & 0 deletions sort/Code_2751.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package sort;

import java.util.Arrays;
import java.util.Scanner;
/*
* �ۼ��� : 2018�� 08�� 16��
* �� �� : �� �����ϱ�2
*/
public class Code_2751 {

public static void main(String[] args) {
// TODO Auto-generated method stub

Scanner sc = new Scanner(System.in);

int num = sc.nextInt();

int[] arr = new int[num];

for(int i=0; i<num; ++i) {
arr[i] = sc.nextInt();
}

Arrays.sort(arr);

for(int i : arr)
System.out.println(i);
}

}