10818번: 최소, 최대
첫째 줄에 정수의 개수 N (1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄에는 N개의 정수를 공백으로 구분해서 주어진다. 모든 정수는 -1,000,000보다 크거나 같고, 1,000,000보다 작거나 같은 정수이다.
www.acmicpc.net
import java.util.Scanner;
import java.util.Arrays;
public class Main
{
public static void main(String[] args) {
int n;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int[] nlist= new int[n];
for (int i=0;i<n;i++){
nlist[i] = sc.nextInt();
}
Arrays.sort(nlist);
System.out.println(nlist[0]+" "+ nlist[n-1]);
}
}
4344번: 평균은 넘겠지
대학생 새내기들의 90%는 자신이 반에서 평균은 넘는다고 생각한다. 당신은 그들에게 슬픈 진실을 알려줘야 한다.
www.acmicpc.net
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n1;
int n2;
int n3;
n1 = sc.nextInt();
for(int i=0;i<n1;i++){
n2 = sc.nextInt();
int[] nlist = new int[n2];
int hap = 0;
double result = 0;
for(int j=0;j<n2;j++){
n3 = sc.nextInt();
nlist[j] = n3;
hap += n3;
}
for(int j=0;j<n2;j++){
if(nlist[j]>(hap/n2)){
result+=1;
}
}
System.out.printf("%.3f%%\n", (result/n2)*100);
}
}
}
8958번: OX퀴즈
"OOXXOXXOOO"와 같은 OX퀴즈의 결과가 있다. O는 문제를 맞은 것이고, X는 문제를 틀린 것이다. 문제를 맞은 경우 그 문제의 점수는 그 문제까지 연속된 O의 개수가 된다. 예를 들어, 10번 문제의 점수
www.acmicpc.net
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n1;
n1 = sc.nextInt();
String slist;
for(int i=0;i<n1;i++){
slist = sc.next();
int count = 0;
int result = 0;
for(int j=0;j<slist.length();j++){
if(slist.charAt(j) == 'O'){
count +=1;
}
else{
count = 0;
}
result += count;
}
System.out.println(result);
}
}
}
3052번: 나머지
각 수를 42로 나눈 나머지는 39, 40, 41, 0, 1, 2, 40, 41, 0, 1이다. 서로 다른 값은 6개가 있다.
www.acmicpc.net
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n1[] = new int[10];
int result = 0;
for(int i=0;i<10;i++){
n1[i] = sc.nextInt() % 42;
}
for(int i=0;i<10;i++){
int n2=0;
for(int j=i+1; j<10; j++){
if(n1[i] == n1[j]){
n2+=1;
}
}
if (n2 == 0){
result +=1;
}
}
System.out.println(result);
}
}
15596번: 정수 N개의 합 (acmicpc.net)
15596번: 정수 N개의 합
C++17, Java 8, Python 3, C11, PyPy3, C99, C++98, C++11, C++14, Go, C99 (Clang), C++98 (Clang), C++11 (Clang), C++14 (Clang), C11 (Clang), C++17 (Clang)
www.acmicpc.net
class Test
{
long sum(int[] nlist){
long result=0;
for (int i=0;i<nlist.length;i++){
result += nlist[i];
}
return result;
}
}'2022 > JAVA' 카테고리의 다른 글
| ep 05-2. 문제 풀이 (0) | 2022.12.02 |
|---|---|
| ep 05-1.추상 클래스 (0) | 2022.12.02 |
| ep 04-2. 상속과 다형성 (0) | 2022.11.27 |
| ep 04-1. 배열과 ArrayList (0) | 2022.11.27 |
| ep 03-4. 문제 풀이2 (0) | 2022.11.20 |