Skip to content

Commit

Permalink
Merge pull request #171 from 1821-Study/sa11k
Browse files Browse the repository at this point in the history
Feat:Add solution of #118
  • Loading branch information
Dltmd202 authored Jul 27, 2022
2 parents 1153f3a + a11f007 commit 918ecf9
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/BaekJoon/sa11k/10773/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.io.*;
import java.util.*;

class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int K = Integer.parseInt(br.readLine());
Stack<Integer> stack = new Stack<>();

for(int i = 0; i<K; i++){
int num = Integer.parseInt(br.readLine());
if(num != 0) stack.push(num);
else stack.pop();
}

int sum = 0;
int size = stack.size();
for(int i = 0; i<size; i++){
sum += stack.pop();
}

System.out.println(sum);

br.close();
}
}
41 changes: 41 additions & 0 deletions src/BaekJoon/sa11k/10814/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main{
public static class Person implements Comparable<Person>{
int age;
String name;

Person(int age, String name){
this.age = age;
this.name = name;
}

@Override
public int compareTo(Person o) {
return this.age - o.age;
}
}

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
Person[] person = new Person[N];

for(int i = 0; i<N; i++){
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
person[i] = new Person(Integer.parseInt(st.nextToken()), st.nextToken());
}

Arrays.sort(person);

for(int i = 0; i<N; i++){
System.out.println(person[i].age + " " + person[i].name);
}

br.close();
}
}

0 comments on commit 918ecf9

Please sign in to comment.