File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package codeup100 ;
22
3+ import java .io .BufferedReader ;
4+ import java .io .IOException ;
5+ import java .io .InputStreamReader ;
36import java .util .Scanner ;
47
58public class c1080 {
6- public static void main (String [] args ) {
9+ public static void main (String [] args ) throws IOException {
10+ //sol1 Memory 14952 Runtime 113
11+ /*
712 Scanner sc = new Scanner(System.in);
813 int num = sc.nextInt();
914 sc.close();
1015
1116 int sum = 0;
1217 int i;
13-
14- //내코드
15- /*
1618 for(i = 1; sum < num; i++){
1719 sum += i;
1820 }
1921 System.out.println(i-1);
20- */
22+ */
2123
22- //두번째코드
23- for (i =1 ; i <num ; i ++){
24- sum += i ;
25- if (sum >= num ) break ;
24+ //sol2
25+ // Using sc.close() : Memory 14348 Runtime 114
26+ // Not using sc.close() : Memory 14312 Runtime 112
27+ /*
28+ Scanner sc = new Scanner(System.in);
29+ int sum = sc.nextInt();
30+ sc.close();
31+
32+ int tempSum = 0;
33+ int i = 0;
34+ for(i=0; tempSum < sum; i++){
35+ tempSum += i;
36+ if(tempSum >= sum) break;
2637 }
2738 System.out.println(i);
39+ */
40+
41+ //sol3 : use BufferReader
42+ //Memory 11128 Runtime 66
43+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
44+ int sum = Integer .parseInt (br .readLine ());
45+ int tempSum = 0 ;
46+ int j = 0 ;
47+ for (j =0 ; tempSum < sum ; j ++){
48+ tempSum += j ;
49+ if (tempSum >= sum ) break ;
50+ }
51+ System .out .println (j );
2852 }
2953}
You can’t perform that action at this time.
0 commit comments