728x90
SMALL

using System;

public class Solution {
    public int[] solution(int[] numbers) {
        int[] answer = new int[numbers.Length];


        for(int i=0;i<numbers.Length;i++)
            answer[i] = numbers[i] * 2;
        return answer;
    }
}

728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(int n, int k) {
        if(n < 1000 && n > 0 && k >= n/10 && k < 1000)
        {
            return 12000*n + 2000*(k-n/10);
        }
        else return 0;
    }
}

 

// 양꼬치를 10개 이상 먹으면 1개 음료수를 서비스 주니까 k에다가 n/10을 마이너스했다.

 

파이썬

 

def solution(n, k):
    return 12000 * n + 2000 * (k - n // 10)

 

자바

 

class Solution {
    public int solution(int n, int k) {
        return n * 12000 + k * 2000 - (n / 10 * 2000);
    }
}

 

728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(int[] array, int n) {
        int answer = 0;
        for(int i = 0; i < array.Length; i++)
        {
            if(array[i] == n) // 어레이의 몇 번째에 n이랑 같은 게 있는 지 확인하기
            {
                answer++;
            }
        }
        return answer;
    }
}

 

 

//////

 

 

using System;

public class Solution {
    public int solution(int[] array, int n) {
        int answer = 0;
        foreach (var it in array)
        {
            if (it == n)
            {
                answer++;
            }
        }
        return answer;
    }
}

 

 

//foreach로 꼭 it라고 하지 않아도 된다.

 

파이썬

 

 

def solution(array, n):
    return array.count(n)

 

 

 

자바

 

 

 

class Solution {
    public int solution(int[] array, int n) {
        int answer = 0;
        
        for (int num : array) 
        {
            if (num == n) answer++;
        }
        return answer;
    }
}

 

728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public double solution(int[] numbers) {
        double answer = 0;
        for (int i = 0; i < numbers.Length; i++)
        {
           if(numbers.Length < 101 && numbers.Length >0 && numbers[i] >= 0 && numbers[i] <= 1000)
          {
            answer += numbers[i];
          }
        }
        return answer/numbers.Length;
    }
}

 

///

 

using System;
using System.Linq;
public class Solution {
    public double solution(int[] numbers) {
        return numbers.Average();
    }
}

//linq로 Average()를 하면 평균값이 출력이 되는 것이다. 변수형은 double을 사용했다.

 

파이썬

 

def solution(numbers):
    return sum(numbers) / len(numbers)

 

자바

 

import java.util.Arrays;

class Solution {
    public double solution(int[] numbers) {
        return Arrays.stream(numbers).average().orElse(0);
    }
}

 

 

class Solution {
    public double solution(int[] numbers) {
        double answer = 0;

        for(int i = 0 ; i < numbers.length ; i++)
        {
            answer += numbers[i];
        }

        return answer/numbers.length;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

public class Solution {
    public int solution(int n) {
        int answer = 0;
        int k;
     if(n<=1000 || n>0)
     {
      for(k=1; k<=n/2; k++)
       {
          answer += 2*k;
       }   
     }
        return answer;
    }
}

 

///

 

using System;

public class Solution {
    public int solution(int n) {
        int answer = 0;

        for(int i = 0; i <= n; i++)
        {
            if(i % 2 == 0) answer += i;
        }

        return answer;
    }
}

 

/////

파이썬

 

def solution(n):
    return sum([i for i in range(2, n + 1, 2)])

//////

def solution(n):
    return 2*(n//2)*((n//2)+1)/2

 

 

자바

 

class Solution {
    public int solution(int n) {
        int answer = 0;

        for(int i=2; i<=n; i+=2)
        {
            answer+=i;
        }

        return answer;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(int angle) {
        if(angle < 90 && angle > 0)
        {
            return 1;
        } //0에서 90도는 1을 리턴
        else if(angle == 90)
        {
            return 2;
        } // 90도면 2리턴
        else if(angle < 180 && angle > 90)
        {
            return 3;
        } //90도 초과 180도 미만이면 3을 리턴
        else return 4; // 나머지(180도)는 4를 리턴
    }
}

 

///

 

using System;

public class Solution {
    public int solution(int angle) {
        int answer = angle < 90 ? 1 : angle == 90 ? 2 : angle < 180 ? 3 : 4;
        return answer;
    }
}

 

/////

 

def solution(angle):
    answer = (angle // 90) * 2 + (angle % 90 > 0) * 1
    return answer

 

/////

 

def solution(angle):
    if angle<=90:
        return 1 if angle<90 else 2
    else:
        return 3 if angle<180 else 4

 

자바

 

//////

 

class Solution {
    public int solution(int angle) {
        return angle == 180 ? 4 : angle < 90 ? 1 : angle == 90 ? 2 : angle > 90 ? 3 : 0;
    }
}
728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(int num1, int num2) {
        if (num1 < 0 || num1 > 10000 || num2 < 0 || num2 > 10000) {
            throw new Exception("invalid param");
        }
        if(num1 == num2)
        {
            return 1;
        }
        else return -1;
    }
}

 

////

파이썬

def solution(num1, num2):
    return 1 if num1==num2 else -1

 

자바

////////////

 

class Solution {
    public int solution(int num1, int num2) {
        int answer = (num1 == num2) ? 1 : -1;
        return answer;
    }
}

 

728x90

설정

트랙백

댓글

728x90
SMALL

using System;

public class Solution {
    public int solution(int age) {
        if (age > 120 || age <= 0) 
        {
            throw new Exception("invalid param");
        }
        return 2023-age;
    }
}

 

/////

파이썬

////

def solution(age):
    return 2023-age

 

자바

 

class Solution {
    public int solution(int age) {
        return 2022-age+1;
    }
}
728x90

설정

트랙백

댓글