-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #171 from 1821-Study/sa11k
Feat:Add solution of #118
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |