검색결과 리스트
프로그래머스에 해당되는 글 199건
- 2023.02.05 프로그래머스 C# 음양 더하기(파이썬, 자바)
- 2023.02.04 프로그래머스 C# H-Index(Array.Sort(), 파이썬, 자바)
- 2023.02.04 프로그래머스 C# 배열 두 배 만들기(P, J)
- 2023.02.02 프로그래머스 C# 몫 구하기(개쉬움, 파이썬, 자바)
- 2023.02.01 프로그래머스 C# 이진 변환 반환하기(이진수, 이진법 Convert.ToString)
- 2023.02.01 프로그래머스 C# 내적
- 2023.01.28 프로그래머스 C# OX퀴즈(JAVA)
- 2023.01.28 프로그래머스 C# 나머지 한 점 좌표 출력(직사각형, XOR)
글
프로그래머스 C# 음양 더하기(파이썬, 자바)
using System;
public class Solution {
public int solution(int[] absolutes, bool[] signs) {
int answer = 0;
for(int i = 0;i<absolutes.Length;i++)
{
if(signs[i] == true)
{
answer += absolutes[i];
}
else
{
answer += -1 * absolutes[i];
}
}
return answer;
}
}
////////
파이썬
def solution(absolutes, signs):
answer=0
for absolute,sign in zip(absolutes,signs):
if sign:
answer+=absolute
else:
answer-=absolute
return answer
자바
//////
class Solution {
public int solution(int[] absolutes, boolean[] signs) {
int answer = 0;
for (int i=0; i<signs.length; i++)
answer += absolutes[i] * (signs[i]? 1: -1);
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 레벨1 C# 삼총사(3중 for문, 파이썬, 자바) (0) | 2023.02.05 |
---|---|
프로그래머스 C# 나머지가 1이 되는 수 찾기(파이썬, 자바) (0) | 2023.02.05 |
프로그래머스 C# H-Index(Array.Sort(), 파이썬, 자바) (0) | 2023.02.04 |
프로그래머스 C# 배열 두 배 만들기(P, J) (0) | 2023.02.04 |
프로그래머스 C# 몫 구하기(개쉬움, 파이썬, 자바) (0) | 2023.02.02 |
글
프로그래머스 C# H-Index(Array.Sort(), 파이썬, 자바)
using System;
using System.Linq;
public class Solution {
public int solution(int[] citations) {
int answer = 0;
Array.Sort(citations);
Array.Reverse(citations);
for(int i = 0;i<citations.Length;i++)
{
if(citations[i] >= i+1)
{
answer++;
}
}
return answer;
}
}
/////////////
//이건 아무리 봐도 설명이 부실했다. 예에 나온 것처럼 [3, 0, 6, 1, 5] 일때 인용이 많은 순서대로 정렬한 [6,5,3,1,0]에서 0번째 인덱스는 1보다 커야하고 1번째 인덱스는 2보다 커야하는 식으로
///내림차순으로 정렬된 어레이에서 처음부터 i 번째 어레이의 인덱스가 i+1보다 크지 않은 첫 번째 경우가 나올 때까지의 갯수를 구하는 건데 약간 설명이 애매하게 돼 있다.
파이썬
def solution(citations):
citations.sort(reverse=True)
answer = max(map(min, enumerate(citations, start=1)))
return answer
/////
def solution(citations):
citations = sorted(citations)
l = len(citations)
for i in range(l):
if citations[i] >= l-i:
return l-i
return 0
자바
import java.util.Arrays;
class Solution {
public int solution(int[] citations) {
int answer = 0;
Arrays.sort(citations);
for(int i=0; i<citations.length; i++)
{
int smaller = Math.min(citations[i], citations.length-i);
answer = Math.max(answer, smaller);
}
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 나머지가 1이 되는 수 찾기(파이썬, 자바) (0) | 2023.02.05 |
---|---|
프로그래머스 C# 음양 더하기(파이썬, 자바) (0) | 2023.02.05 |
프로그래머스 C# 배열 두 배 만들기(P, J) (0) | 2023.02.04 |
프로그래머스 C# 몫 구하기(개쉬움, 파이썬, 자바) (0) | 2023.02.02 |
프로그래머스 C# 이진 변환 반환하기(이진수, 이진법 Convert.ToString) (0) | 2023.02.01 |
글
프로그래머스 C# 배열 두 배 만들기(P, J)
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;
}
}
/////
파이썬
/////
def solution(numbers):
return [num*2 for num in numbers]
자바
class Solution {
public int[] solution(int[] numbers) {
int[] answer = {};
answer = new int[numbers.length];
for(int i=0; i<answer.length; i++)
{
answer[i] = numbers[i]*2;
}
return answer;
}
}
import java.util.*;
class Solution {
public ArrayList solution(int[] numbers) {
ArrayList<Integer> answer = new ArrayList<>();
for(int num : numbers)
{
answer.add(num*2);
}
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 음양 더하기(파이썬, 자바) (0) | 2023.02.05 |
---|---|
프로그래머스 C# H-Index(Array.Sort(), 파이썬, 자바) (0) | 2023.02.04 |
프로그래머스 C# 몫 구하기(개쉬움, 파이썬, 자바) (0) | 2023.02.02 |
프로그래머스 C# 이진 변환 반환하기(이진수, 이진법 Convert.ToString) (0) | 2023.02.01 |
프로그래머스 C# 내적 (0) | 2023.02.01 |
글
프로그래머스 C# 몫 구하기(개쉬움, 파이썬, 자바)
using System;
public class Solution {
public int solution(int num1, int num2) {
int answer = num1/num2;
return answer;
}
}
파이썬
def solution(num1, num2):
return num1 // num2
////////
solution = int.__floordiv__
JAVA
class Solution {
public int solution(int num1, int num2) {
return num1/num2;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# H-Index(Array.Sort(), 파이썬, 자바) (0) | 2023.02.04 |
---|---|
프로그래머스 C# 배열 두 배 만들기(P, J) (0) | 2023.02.04 |
프로그래머스 C# 이진 변환 반환하기(이진수, 이진법 Convert.ToString) (0) | 2023.02.01 |
프로그래머스 C# 내적 (0) | 2023.02.01 |
C# 부족한 금액 계산하기 (0) | 2023.01.31 |
글
프로그래머스 C# 이진 변환 반환하기(이진수, 이진법 Convert.ToString)
using System;
public class Solution {
public int[] solution(string s) {
int[] answer = new int[2];
int index = 0;
int i = 0;
while(s != "1")
{
int length = s.Length;
s = s.Replace("0", "");
index++;
length = length - s.Length;
i += length;
s = Convert.ToString(s.Length, 2);
}
answer[0] = index;
answer[1] = i;
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 배열 두 배 만들기(P, J) (0) | 2023.02.04 |
---|---|
프로그래머스 C# 몫 구하기(개쉬움, 파이썬, 자바) (0) | 2023.02.02 |
프로그래머스 C# 내적 (0) | 2023.02.01 |
C# 부족한 금액 계산하기 (0) | 2023.01.31 |
LG CNS 스마트팩토리(미국) 코딩 테스트 본 사람은 없나... (0) | 2023.01.29 |
글
프로그래머스 C# 내적
using System;
public class Solution {
public int solution(int[] a, int[] b) {
int answer = 0;
for(int i =0;i<a.Length;i++)
{
answer += a[i] * b[i];
}
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 몫 구하기(개쉬움, 파이썬, 자바) (0) | 2023.02.02 |
---|---|
프로그래머스 C# 이진 변환 반환하기(이진수, 이진법 Convert.ToString) (0) | 2023.02.01 |
C# 부족한 금액 계산하기 (0) | 2023.01.31 |
LG CNS 스마트팩토리(미국) 코딩 테스트 본 사람은 없나... (0) | 2023.01.29 |
C# ASCII(아스키) 코드 숫자로 변환하기 (0) | 2023.01.29 |
글
프로그래머스 C# OX퀴즈(JAVA)
public class Solution {
public string[] solution(string[] quiz) {
string[] answer = new string[quiz.Length];
for(int i = 0; i < quiz.Length; i++)
{
answer[i] = oxCheck(quiz[i].Split(" "));
}
return answer;
}
public string oxCheck(string[] str)
{
int num = int.Parse(str[0]);
/// 첫 번째 숫자
for(int i = 1; i < str.Length; i++) // 1부터 한다.
{
///홀수 번째 일때는 연산자니까
if(i % 2 != 0)
{
if(str[i].Equals("+"))
{
num += int.Parse(str[i + 1]);
/// 플러스면 더하고
}
else if(str[i].Equals("-"))
{
num -= int.Parse(str[i + 1]);
/// 마이너스면 뺀다.
}
else
{
if(int.Parse(str[i + 1]) == num)
{
return "O";
}
else
{
return "X";
}
}
}
}
return "";
}
}
자바
class Solution {
public String[] solution(String[] quiz) {
int size = quiz.length;
String[] answer = new String[size];
for (int i = 0; i < answer.length; i++)
{
String[] splitQ = quiz[i].trim().split(" ");
int X = Integer.parseInt(splitQ[0]);
int Y = Integer.parseInt(splitQ[2]);
int Z = Integer.parseInt(splitQ[4]);
int cal = 0;
if(splitQ[1].equals("-"))
{
cal = X - Y;
}
else
{
cal = X + Y;
}
answer[i] = Z == cal ? "O" : "X";
}
return answer;
}
}
class Solution {
public String[] solution(String[] quiz) {
String[] answer = new String[quiz.length];
for(int i=0; i<quiz.length; i++)
{
String[] temp = quiz[i].split(" ");
if(temp[0].isEmpty())
{
answer[i]="O";
continue;
}
Integer first = Integer.parseInt(temp[0]);
String oper = temp[1];
Long second = Long.parseLong(temp[2]);
Integer result = Integer.parseInt(temp[4]);
if(oper.equals("+"))
{
if(first+second==result)
{
answer[i] = "O";
}
else
{
answer[i] = "X";
}
}
else
{
if(first-second==result)
{
answer[i] = "O";
}
else
{
answer[i] = "X";
}
}
}
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
C# ASCII(아스키) 코드 숫자로 변환하기 (0) | 2023.01.29 |
---|---|
C# 카펫 - 완전탐색 (0) | 2023.01.29 |
프로그래머스 C# 빈칸 채우기(예시) (0) | 2023.01.28 |
프로그래머스 C# 나머지 한 점 좌표 출력(직사각형, XOR) (0) | 2023.01.28 |
C# 가장 큰 수(foreach, CompareTo, var, string.Join) (0) | 2023.01.27 |
글
프로그래머스 C# 나머지 한 점 좌표 출력(직사각형, XOR)
using System;
class Solution
{
public int[] solution(int[,] v)
{
int[] answer={0,0};
answer[0] = v[0,0] ^ v[1,0] ^ v[2,0];
answer[1] = v[0,1] ^ v[1,1] ^ v[2,1];
return answer;
}
}
///////
int[] answer = new int[2];
for(int i=0; i<answer.Length;i++)
{
if(v[0][i] == v[1][i])
{
answer = v[2][i];
}
else if(v[0][i] == v[2][i])
{
answer = v[1][i];
}
else if(v[1][i] == v[2][i])
{
answer = v[0][i];
}
}
return answer;
A XOR B = 0
A XOR A XOR B = B
같은 값 두개와 다른 값 하나를 XOR하면 다른 값 한개가 나옴
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# OX퀴즈(JAVA) (0) | 2023.01.28 |
---|---|
프로그래머스 C# 빈칸 채우기(예시) (0) | 2023.01.28 |
C# 가장 큰 수(foreach, CompareTo, var, string.Join) (0) | 2023.01.27 |
C# 디스크 컨트롤러(다른 사람의 풀이) (0) | 2023.01.27 |
C# 단어 변환(DFS, 깊이 우선 탐색) (0) | 2023.01.27 |