알고리즘 정리/[swea]
[swea] 공부기록 day04
로미로미로
2024. 5. 8. 08:47
1970. 쉬운 거스름돈
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
for(int i=0; i<n; i++)
{
int a=0;
int b=0;
int c=0;
int d=0;
int e=0;
int f=0;
int g=0;
int h=0;
int N = scan.nextInt();
if(N/50000>= 0) {
a = N/50000;
N = N - a*50000;
}
if(N/10000 >= 0) {
b = N/10000;
N = N - b*10000;
}
if(N/5000 >= 0) {
c = N/5000;
N = N - c*5000;
}
if(N/1000 >= 0) {
d = N/1000;
N = N - d*1000;
}
if(N/500 >= 0) {
e = N/500;
N = N -e*500;
}
if(N/100 >= 0) {
f = N/100;
N = N - f*100;
}
if(N/50 >= 0) {
g = N/50;
N = N - g*50;
}
if(N/10 >= 0) {
h = N/10;
N = N - h*10;
}
System.out.printf("#%d\n%d %d %d %d %d %d %d %d\n", i+1, a, b, c, d, e, f, g, h);
}
}
}
1983. 조교의 성적 매기기
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String [] count = {"A+","A0","A-","B+","B0","B-","C+","C0","C-","D0"};
int n = scan.nextInt();
for(int i=0; i<n; i++) {
int N = scan.nextInt();
int K = scan.nextInt();
int [][] arr = new int[N][3];
double [] point = new double[N];
for(int j=0; j<N; j++) {
for(int k=0; k<3; k++) {
arr[j][k] = scan.nextInt();
}
}
for(int j=0; j<N; j++) {
point[j] = arr[j][0]*0.35 + arr[j][1]*0.45 + arr[j][2]*0.2;
}
int c=1;
for(int j=0; j<N; j++) {
if(point[j] > point[K-1])
c+=1;
}
//c는 K의 순위.
int s = N/10;
c = (int) Math.ceil((double) c / s);
System.out.printf("#%d %s\n",i+1,count[c-1]);
}
}
}
1946. 간단한 압축 풀기
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
for(int i=0; i<T; i++) {
int N = scan.nextInt();
String [] S = new String[N];
int [] C = new int[N];
for(int j=0; j<N; j++) {
S[j] = scan.next();
C[j] = scan.nextInt();
S[j] = repeat(S[j], C[j]);
}
for(int j=1; j<N; j++) {
S[0] += S[j];
}
System.out.printf("#%d\n", i+1);
for(int j=0; j<S[0].length()/10; j++) {
for(int k=0; k<10; k++) {
System.out.printf("%s", S[0].charAt(k+j*10));
}
System.out.println();
}
int Num = S[0].length() % 10;
if( Num > 0) {
for(int k=0; k<Num; k++) {
System.out.print(S[0].charAt((S[0].length()/10)*10 + k));
}
}
System.out.println();
}
}
private static String repeat(String S, int N) {
String SS = "";
for(int i=0; i<N; i++) {
SS += S;
}
return SS;
}
}
1204. 최빈수 구하기
import java.util.Arrays;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
for(int i=0; i<T; i++) {
int max =0 ;
int num = 0;
int n = scan.nextInt();
int [] arr = new int[101];
for(int j=0; j<1000; j++) {
int s = scan.nextInt();
arr[s] ++;
}
for(int j=0; j<101; j++) {
if(max <= arr[j]) {
max = arr[j];
num = j;
}
}
System.out.printf("#%d %d\n",n, num);
}
}
}
1984. 중간 평균값 구하기
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
for(int i=0; i<T; i++) {
int [] arr = new int[10];
int max = 0;
int min = 10000;
int plus =0;
for(int j=0; j<10; j++) {
arr[i] = scan.nextInt();
if(max < arr[i])
max = arr[i];
if(min > arr[i])
min = arr[i];
plus += arr[i];
}
int avg = Math.round((float)(plus-min-max)/8);
System.out.printf("#%d %d\n", i+1,avg);
}
}
}]