검색결과 리스트
프로그래머스에 해당되는 글 199건
- 2022.12.20 프로그래머스 C# 배열 안에 있는 수를 2배씩 하기(배열의 상수 곱셈)
- 2022.12.20 프로그래머스 C# 양꼬치(다항식 세우기, P, J)
- 2022.12.20 프로그래머스 C# 중복된 숫자 개수(array, foreach 간단한 사용법, P, J)
- 2022.12.20 프로그래머스 C# 배열의 평균값(Linq, Average 평균)
- 2022.12.20 프로그래머스 C# 짝수의 합(for문 줄이기, P, J)
- 2022.12.19 프로그래머스 C# 각도기(if, else if, else문, 삼항 연산자, P, J)
- 2022.12.19 프로그래머스 C# 숫자 비교하기(개쉬움, P, J)
- 2022.12.19 프로그래머스 C# 나이 출력(개쉬움, P, J)
글
프로그래머스 C# 배열 안에 있는 수를 2배씩 하기(배열의 상수 곱셈)
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;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 배열 뒤집기(for문 역순으로 출력, Reverse, Linq / ToArray, P, J) (0) | 2022.12.20 |
---|---|
프로그래머스 C# 머쓱이보다 키 큰 사람(array 숫자 비교하기, P, J) (0) | 2022.12.20 |
프로그래머스 C# 양꼬치(다항식 세우기, P, J) (0) | 2022.12.20 |
프로그래머스 C# 중복된 숫자 개수(array, foreach 간단한 사용법, P, J) (0) | 2022.12.20 |
프로그래머스 C# 배열의 평균값(Linq, Average 평균) (0) | 2022.12.20 |
글
프로그래머스 C# 양꼬치(다항식 세우기, P, J)
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);
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 머쓱이보다 키 큰 사람(array 숫자 비교하기, P, J) (0) | 2022.12.20 |
---|---|
프로그래머스 C# 배열 안에 있는 수를 2배씩 하기(배열의 상수 곱셈) (0) | 2022.12.20 |
프로그래머스 C# 중복된 숫자 개수(array, foreach 간단한 사용법, P, J) (0) | 2022.12.20 |
프로그래머스 C# 배열의 평균값(Linq, Average 평균) (0) | 2022.12.20 |
프로그래머스 C# 짝수의 합(for문 줄이기, P, J) (0) | 2022.12.20 |
글
프로그래머스 C# 중복된 숫자 개수(array, foreach 간단한 사용법, P, J)
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;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 배열 안에 있는 수를 2배씩 하기(배열의 상수 곱셈) (0) | 2022.12.20 |
---|---|
프로그래머스 C# 양꼬치(다항식 세우기, P, J) (0) | 2022.12.20 |
프로그래머스 C# 배열의 평균값(Linq, Average 평균) (0) | 2022.12.20 |
프로그래머스 C# 짝수의 합(for문 줄이기, P, J) (0) | 2022.12.20 |
프로그래머스 C# 각도기(if, else if, else문, 삼항 연산자, P, J) (0) | 2022.12.19 |
글
프로그래머스 C# 배열의 평균값(Linq, Average 평균)
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;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 양꼬치(다항식 세우기, P, J) (0) | 2022.12.20 |
---|---|
프로그래머스 C# 중복된 숫자 개수(array, foreach 간단한 사용법, P, J) (0) | 2022.12.20 |
프로그래머스 C# 짝수의 합(for문 줄이기, P, J) (0) | 2022.12.20 |
프로그래머스 C# 각도기(if, else if, else문, 삼항 연산자, P, J) (0) | 2022.12.19 |
프로그래머스 C# 숫자 비교하기(개쉬움, P, J) (0) | 2022.12.19 |
글
프로그래머스 C# 짝수의 합(for문 줄이기, P, J)
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;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 중복된 숫자 개수(array, foreach 간단한 사용법, P, J) (0) | 2022.12.20 |
---|---|
프로그래머스 C# 배열의 평균값(Linq, Average 평균) (0) | 2022.12.20 |
프로그래머스 C# 각도기(if, else if, else문, 삼항 연산자, P, J) (0) | 2022.12.19 |
프로그래머스 C# 숫자 비교하기(개쉬움, P, J) (0) | 2022.12.19 |
프로그래머스 C# 나이 출력(개쉬움, P, J) (0) | 2022.12.19 |
글
프로그래머스 C# 각도기(if, else if, else문, 삼항 연산자, P, J)
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;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 배열의 평균값(Linq, Average 평균) (0) | 2022.12.20 |
---|---|
프로그래머스 C# 짝수의 합(for문 줄이기, P, J) (0) | 2022.12.20 |
프로그래머스 C# 숫자 비교하기(개쉬움, P, J) (0) | 2022.12.19 |
프로그래머스 C# 나이 출력(개쉬움, P, J) (0) | 2022.12.19 |
프로그래머스 C# 두 수의 차, 두 수의 곱, 나머지 구하기(개쉬움) (0) | 2022.12.19 |
글
프로그래머스 C# 숫자 비교하기(개쉬움, P, J)
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;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 짝수의 합(for문 줄이기, P, J) (0) | 2022.12.20 |
---|---|
프로그래머스 C# 각도기(if, else if, else문, 삼항 연산자, P, J) (0) | 2022.12.19 |
프로그래머스 C# 나이 출력(개쉬움, P, J) (0) | 2022.12.19 |
프로그래머스 C# 두 수의 차, 두 수의 곱, 나머지 구하기(개쉬움) (0) | 2022.12.19 |
일본의 프로그래밍 경기 AtCoder (0) | 2021.03.21 |
글
프로그래머스 C# 나이 출력(개쉬움, P, J)
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;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 각도기(if, else if, else문, 삼항 연산자, P, J) (0) | 2022.12.19 |
---|---|
프로그래머스 C# 숫자 비교하기(개쉬움, P, J) (0) | 2022.12.19 |
프로그래머스 C# 두 수의 차, 두 수의 곱, 나머지 구하기(개쉬움) (0) | 2022.12.19 |
일본의 프로그래밍 경기 AtCoder (0) | 2021.03.21 |
비주얼 스튜디오 단축키 정리 (0) | 2021.03.01 |