forked from sowon-dev/AlgorithmStudy_Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc1080.java
More file actions
53 lines (47 loc) ยท 1.32 KB
/
c1080.java
File metadata and controls
53 lines (47 loc) ยท 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package codeup100;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class c1080 {
public static void main(String[] args) throws IOException {
//sol1 Memory 14952 Runtime 113
/*
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
sc.close();
int sum = 0;
int i;
for(i = 1; sum < num; i++){
sum += i;
}
System.out.println(i-1);
*/
//sol2
// Using sc.close() : Memory 14348 Runtime 114
// Not using sc.close() : Memory 14312 Runtime 112
/*
Scanner sc = new Scanner(System.in);
int sum = sc.nextInt();
sc.close();
int tempSum = 0;
int i = 0;
for(i=0; tempSum < sum; i++){
tempSum += i;
if(tempSum >= sum) break;
}
System.out.println(i);
*/
//sol3 : use BufferReader
//Memory 11128 Runtime 66
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int sum = Integer.parseInt(br.readLine());
int tempSum = 0;
int j = 0;
for(j=0; tempSum < sum; j++){
tempSum += j;
if(tempSum >= sum) break;
}
System.out.println(j);
}
}