알고리즘
[softeer] 근무시간, 바이러스 JAVA | scanner, substring, Integer.parseInt, Int scanner.nextInt(),
wjdwwidz
2024. 10. 31. 17:25
https://softeer.ai/practice/6254
Softeer - 현대자동차그룹 SW인재확보플랫폼
softeer.ai
근무시간
import java.util.*;
import java.lang.*;
import java.io.*;
// The main method must be in a class named "Main".
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int total = 0;
for (int i =0; i<5; i++) {
String startTime = sc.next();
String endTime = sc.next();
int startH = Integer.parseInt(startTime.substring(0,2));
int startMin = Integer.parseInt(startTime.substring(3,5));
int endH = Integer.parseInt(endTime.substring(0,2));
int endMin = Integer.parseInt(endTime.substring(3,5));
total += (60-startMin) + (endH - startH -1 ) * 60 + endMin;
}
System.out.println(total);
sc.close();
}
}
https://softeer.ai/practice/6284
Softeer - 현대자동차그룹 SW인재확보플랫폼
softeer.ai
바이러스
- nextInt()를 사용하여 int 형으로 계산
(K*P*N) %1000000007 로 계산하였으나 계산에 오류가 있었다.
import java.util.*;
import java.lang.*;
import java.io.*;
// The main method must be in a class named "Main".
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int K = sc.nextInt();
int P = sc.nextInt();
int N = sc.nextInt();
int result = K;
for (int i = 1; i<=N; i++){
result = (result*P)%1000000007;
}
System.out.print(result);
sc.close();
}
}