10월 3일 개인공부

안효빈·2022년 10월 2일
0

개인 공부

목록 보기
23/36
  1. 코테

  2. 할 수 있으면 자바스크립트, CSS헷갈렸던부분 복습


프로그래머스 코테 [약수의 개수와 덧셈]

class Solution {
    public int solution(int left, int right) {
        int answer = 0;
        
        int sum = 0;
		int sum2 = 0;
        
        for(int i = left; i <= right; i++) {
        	sum += i;
        }
        
        for(int i = 1; i <= 32; i++) {
        	
        	if(i*i >= left && i*i <= right) {
        		
        		sum2 += i*i;
        		
        	}
        	
        }
        
        answer = sum-sum2*2;
        
        return answer;
    }
}

+2점


프로그래머스 코테 [부족한 금액 계산하기]

class Solution {
    public long solution(int price, int money, int count) {
        long answer = 0;
		long total = 0;
		
		
		for(int i = 1; i <= count; i++) {
			total += (long)(price*i);
		}
		
		
		if(money <= total) {
			
			answer = (long)(total - money);
		}else {
			
			answer = 0;
		}
        
        return answer;
    }
}

+8점


프로그래머스 코테 [직사각형 별찍기]

import java.util.Scanner;

class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();

    for(int j = 1; j <= b; j++){
        for(int i = 1; i <= a; i++){
            System.out.print("*");
        }
        System.out.println();
    }
    
}

}

+1점


프로그래머스 코테 [최대공약수와 최소공배수]

import java.util.*;
class Solution {
    public int[] solution(int n, int m) {
        int[] answer = new int[2];
        int b = 0;
        ArrayList<Integer> a = new ArrayList<Integer>();
        
        
        if(n < m){
            for(int i = 1; i <= m; i++){
                if(m % i == 0 && n % i == 0){
                    a.add(i);
                }
            }
        }else{
            for(int i = 1; i <= n; i++){
                if(m % i == 0 && n % i == 0){
                    a.add(i);
                }
            }
        }
            
        int c = a.get(a.size()-1);
        
        System.out.println(c);
        
        answer[0] = c;
        answer[1] = m*n/c; 
        
        return answer;
    }
}

+5점


profile
다들 화이팅

0개의 댓글