검색결과 리스트
프로그래밍에 해당되는 글 340건
- 2022.12.30 프로그래머스 C# 약수 구하기(List.Add, List.ToArray(), P, J)
- 2022.12.30 프로그래머스 C# 가장 큰 수 찾기(array.Max(), Array.IndexOf(array, array.Max()), P, J)
- 2022.12.30 프로그래머스 C# 주사위의 개수(몫 곱하기, P, J)
- 2022.12.29 프로그래머스 C# 가위 바위 보(string +=, 삼항연산자 가능, P, J)
- 2022.12.29 프로그래머스 C# 문자열 정렬하기 (1) (문자열에 있는 숫자를 int로 바꾸기, P, J)
- 2022.12.29 프로그래머스 C# 암호 해독(주기, P, J)
- 2022.12.29 프로그래머스 C# 대문자와 소문자(ToUpper(), ToLower()) Char.ToUpper(스트링), 스트링.ToUpper(),P,J)
- 2022.12.29 프로그래머스 C# 세균 증식(for문 2씩 곱하기, P, J)
글
프로그래머스 C# 약수 구하기(List.Add, List.ToArray(), P, J)
using System;
using System.Collections.Generic;
public class Solution {
public int[] solution(int n) {
List<int> List = new List<int>();
for(int i=1;i<n+1;i++)
{
if(n%i == 0)
{
List.Add(i);
}
}
int[] answer = List.ToArray();
return answer;
}
}
파이썬
def solution(n):
answer = [i for i in range(1,n+1) if n%i == 0]
return answer
자바
import java.util.*;
class Solution {
public int[] solution(int n) {
List<Integer> list = new ArrayList<>();
for (int i = 1; i <= n / 2; i++)
{
if (n % i == 0)
{
list.add(i);
}
}
list.add(n);
return list.stream().mapToInt(e -> e).toArray();
}
}
import java.util.stream.IntStream;
import java.util.Arrays;
class Solution {
public int[] solution(int n) {
return IntStream.rangeClosed(1, n).filter(i -> n % i == 0).toArray();
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 배열 회전시키기(0번, 마지막 배열 처리, P, J) (0) | 2022.12.30 |
---|---|
프로그래머스 C# 최댓값 만들기2(List.Add, List.Max(), Linq, P, J) (0) | 2022.12.30 |
프로그래머스 C# 가장 큰 수 찾기(array.Max(), Array.IndexOf(array, array.Max()), P, J) (0) | 2022.12.30 |
프로그래머스 C# 주사위의 개수(몫 곱하기, P, J) (0) | 2022.12.30 |
프로그래머스 C# 가위 바위 보(string +=, 삼항연산자 가능, P, J) (0) | 2022.12.29 |
글
프로그래머스 C# 가장 큰 수 찾기(array.Max(), Array.IndexOf(array, array.Max()), P, J)
using System;
using System.Linq;
public class Solution {
public int[] solution(int[] array) {
int[] answer = new int[2] {array.Max(), Array.IndexOf(array, array.Max())};
return answer;
}
}
//array.Max()는 배열 원소중 가장 큰수를 반환. Array.IndexOf는 지정한 개체를 검색하여 같은 원소가 있으면 그 인덱스 번호를 반환함
파이썬
def solution(array):
val = max(array)
return [val, array.index(val)]
자바
class Solution {
public int[] solution(int[] array) {
int[] answer = new int[2];
for(int i=0;i<array.length;i++)
{
if(array[i] > answer[0])
{
answer[0] = array[i];
answer[1] = i;
}
}
return answer;
}
}
class Solution {
public int[] solution(int[] array) {
int max = 0;
int maxIndex = -1;
for (int i = 0; i < array.length; i++)
{
if (max < array[i])
{
max = array[i];
maxIndex = i;
}
}
int[] answer = {max, maxIndex};
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 최댓값 만들기2(List.Add, List.Max(), Linq, P, J) (0) | 2022.12.30 |
---|---|
프로그래머스 C# 약수 구하기(List.Add, List.ToArray(), P, J) (0) | 2022.12.30 |
프로그래머스 C# 주사위의 개수(몫 곱하기, P, J) (0) | 2022.12.30 |
프로그래머스 C# 가위 바위 보(string +=, 삼항연산자 가능, P, J) (0) | 2022.12.29 |
프로그래머스 C# 문자열 정렬하기 (1) (문자열에 있는 숫자를 int로 바꾸기, P, J) (0) | 2022.12.29 |
글
프로그래머스 C# 주사위의 개수(몫 곱하기, P, J)
using System;
public class Solution {
public int solution(int[] box, int n) {
int answer = 0;
answer += box[0]/n;
answer *= box[1]/n;
answer *= box[2]/n;
return answer;
}
}
파이썬
def solution(box, n):
x, y, z = box
return (x // n) * (y // n) * (z // n )
자바
class Solution {
public int solution(int[] box, int n) {
int answer = 1;
answer *= box[0]/n;
answer *= box[1]/n;
answer *= box[2]/n;
return answer;
}
}
자바
class Solution {
public int solution(int[] box, int n) {
int answer = 1;
answer *= box[0]/n;
answer *= box[1]/n;
answer *= box[2]/n;
return answer;
}
}
class Solution {
public int solution(int[] box, int n) {
int answer = 0;
for(int length : box)
{
if(answer == 0)
{
answer = length / n;
}
else
{
answer *= length / n;
}
}
return answer;
}
}
class Solution {
public int solution(int[] box, int n) {
int answer = (box[0] / n) * (box[1] / n) * (box[2] / n);
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 약수 구하기(List.Add, List.ToArray(), P, J) (0) | 2022.12.30 |
---|---|
프로그래머스 C# 가장 큰 수 찾기(array.Max(), Array.IndexOf(array, array.Max()), P, J) (0) | 2022.12.30 |
프로그래머스 C# 가위 바위 보(string +=, 삼항연산자 가능, P, J) (0) | 2022.12.29 |
프로그래머스 C# 문자열 정렬하기 (1) (문자열에 있는 숫자를 int로 바꾸기, P, J) (0) | 2022.12.29 |
프로그래머스 C# 암호 해독(주기, P, J) (0) | 2022.12.29 |
글
프로그래머스 C# 가위 바위 보(string +=, 삼항연산자 가능, P, J)
using System;
public class Solution {
public string solution(string rsp) {
string answer = "";
// 2 > 0
// 0 > 5
// 5 > 2
for(int i=0;i<rsp.Length;i++)
{
if(rsp[i].ToString() == "2")
{
answer += "0";
}
else if(rsp[i].ToString() == "0")
{
answer += "5";
}
else
{
answer += "2";
}
}
return answer;
}
}
파이썬
////
def solution(rsp):
rsp =rsp.replace('2','s')
rsp =rsp.replace('5','p')
rsp =rsp.replace('0','r')
rsp =rsp.replace('r','5')
rsp =rsp.replace('s','0')
rsp =rsp.replace('p','2')
return rsp
/////
def solution(rsp):
answer = ''
for i in list(map(int, rsp)):
if i == 0:
answer += str(5)
elif i == 2:
answer += str(0)
else:
answer += str(2)
return answer
자바
class Solution {
public String solution(String rsp) {
char[] cRsp = rsp.toCharArray();
StringBuilder answer = new StringBuilder();
for(int i=0; i < cRsp.length; i++)
{
switch(cRsp[i])
{
case '0' :
answer.append("5");
break;
case '2' :
answer.append("0");
break;
case '5' :
answer.append("2");
break;
}
}
return answer.toString();
}
}
class Solution {
public String solution(String rsp) {
String answer = "";
String[] arr = rsp.split("");
for(int i=0;i < arr.length; i++)
{
if(arr[i].equals("2"))
answer += "0";
else if(arr[i].equals("0"))
answer += "5";
else
answer += "2";
}
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 가장 큰 수 찾기(array.Max(), Array.IndexOf(array, array.Max()), P, J) (0) | 2022.12.30 |
---|---|
프로그래머스 C# 주사위의 개수(몫 곱하기, P, J) (0) | 2022.12.30 |
프로그래머스 C# 문자열 정렬하기 (1) (문자열에 있는 숫자를 int로 바꾸기, P, J) (0) | 2022.12.29 |
프로그래머스 C# 암호 해독(주기, P, J) (0) | 2022.12.29 |
프로그래머스 C# 대문자와 소문자(ToUpper(), ToLower()) Char.ToUpper(스트링), 스트링.ToUpper(),P,J) (0) | 2022.12.29 |
글
프로그래머스 C# 문자열 정렬하기 (1) (문자열에 있는 숫자를 int로 바꾸기, P, J)
using System;
using System.Collections.Generic;
public class Solution {
public int[] solution(string my_string) {
List<int> List = new List<int>();
for(int i = 0; i < my_string.Length; i++)
{
if(Char.IsDigit(my_string[i]) == true)
{
List.Add((int)my_string[i] - 48);
}
}
int[] answer = List.ToArray();
Array.Sort(answer);
return answer;
}
}
///
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
public int[] solution(string my_string) {
int[] answer = my_string.Where(x => char.IsNumber(x)).Select(x => Convert.ToInt32(x.ToString())).OrderBy(x => x).ToArray();
Array.Sort(answer);
return answer;
}
}
파이썬
def solution(my_string):
answer = []
for i in my_string:
if i.isdigit():
answer.append(int(i))
answer.sort()
return answer
////
def solution(my_string):
return sorted([int(c) for c in my_string if c.isdigit()])
//////
자바
//////
import java.util.*;
class Solution {
public int[] solution(String my_string) {
my_string = my_string.replaceAll("[a-z]","");
int[] answer = new int[my_string.length()];
for(int i =0; i<my_string.length(); i++)
{
answer[i] = my_string.charAt(i) - '0';
}
Arrays.sort(answer);
return answer;
}
}
import java.util.*;
class Solution {
public int[] solution(String myString) {
return Arrays.stream(myString.replaceAll("[A-Z|a-z]", "").split("")).sorted().mapToInt(Integer::parseInt).toArray();
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 주사위의 개수(몫 곱하기, P, J) (0) | 2022.12.30 |
---|---|
프로그래머스 C# 가위 바위 보(string +=, 삼항연산자 가능, P, J) (0) | 2022.12.29 |
프로그래머스 C# 암호 해독(주기, P, J) (0) | 2022.12.29 |
프로그래머스 C# 대문자와 소문자(ToUpper(), ToLower()) Char.ToUpper(스트링), 스트링.ToUpper(),P,J) (0) | 2022.12.29 |
프로그래머스 C# 세균 증식(for문 2씩 곱하기, P, J) (0) | 2022.12.29 |
글
프로그래머스 C# 암호 해독(주기, P, J)
using System;
public class Solution {
public string solution(string cipher, int code) {
string answer = "";
for(int i=0;i<cipher.Length;i++)
{
if(i%code == 0 && code+i-1 < cipher.Length && i != 0) //code로 나뉘어지고, cipher.Length+1보다 작은 범위 내에서 출력.
{
answer += cipher[code+i-1];
}
}
return answer;
}
}
////
using System;
public class Solution {
public string solution(string cipher, int code) {
string answer = "";
for(int i=code-1;i<cipher.Length;i+=code)
{
answer+=cipher[i];
}
return answer;
}
}
파이썬
def solution(cipher, code):
answer = cipher[code-1::code]
return answer
자바
import java.util.*;
class Solution {
public String solution(String cipher, int code) {
String[] arr = cipher.split("");
StringBuilder sb = new StringBuilder();
int x = code-1;
while(x < arr.length)
{
sb.append(arr[x]);
x += code;
}
return sb.toString();
}
}
class Solution {
public String solution(String cipher, int code) {
String answer = "";
for(int i=code-1; i<cipher.length(); i+=code)
{
answer += cipher.substring(i, i+1);
}
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 가위 바위 보(string +=, 삼항연산자 가능, P, J) (0) | 2022.12.29 |
---|---|
프로그래머스 C# 문자열 정렬하기 (1) (문자열에 있는 숫자를 int로 바꾸기, P, J) (0) | 2022.12.29 |
프로그래머스 C# 대문자와 소문자(ToUpper(), ToLower()) Char.ToUpper(스트링), 스트링.ToUpper(),P,J) (0) | 2022.12.29 |
프로그래머스 C# 세균 증식(for문 2씩 곱하기, P, J) (0) | 2022.12.29 |
프로그래머스 C# n의 배수 고르기(List.Add, P, J) (0) | 2022.12.29 |
글
프로그래머스 C# 대문자와 소문자(ToUpper(), ToLower()) Char.ToUpper(스트링), 스트링.ToUpper(),P,J)
using System;
public class Solution {
public string solution(string my_string) {
string answer = "";
for(int i = 0; i < my_string.Length; i++)
{
if(Char.IsLower(my_string[i]) == true) //소문자면 대문자로 바꾸기
{
answer += Char.ToUpper(my_string[i]);
}
else
{
answer += Char.ToLower(my_string[i]);
}
}
return answer;
}
}
///
//answer = my_string.ToUpper();
//answer2 = my_string.ToLower();
전부다 대문자 혹은 소문자로 바꾸는 방법은 알았는데 Char.ToLower, Char.ToUpper이런 거는 몰랐다.
using System;
public class Solution {
public string solution(string my_string) {
string answer = "";
foreach (var it in my_string)
{
if ('a' <= it && it <= 'z')
{
answer += it.ToString().ToUpper();
}
else
{
answer += it.ToString().ToLower();
}
}
return answer;
}
}
파이썬
def solution(my_string):
answer = ''
for i in my_string:
if i.isupper():
answer+=i.lower()
else:
answer+=i.upper()
return answer
자바
class Solution {
public String solution(String my_string) {
String answer = "";
for(int i=0; i<my_string.length(); i++)
{
char c = my_string.charAt(i);
if(Character.isUpperCase(c))
{
answer += String.valueOf(c).toLowerCase();
}
else
{
answer += String.valueOf(c).toUpperCase();
}
}
return answer;
}
}
class Solution {
public String solution(String my_string) {
String answer = "";
for (int i = 0; i < my_string.length(); i++)
{
int num = (int)my_string.charAt(i);
if (num >= 65 && num <= 90)
answer += (char)(num + 32) + "";
else
answer += (char)(num - 32) + "";
}
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 문자열 정렬하기 (1) (문자열에 있는 숫자를 int로 바꾸기, P, J) (0) | 2022.12.29 |
---|---|
프로그래머스 C# 암호 해독(주기, P, J) (0) | 2022.12.29 |
프로그래머스 C# 세균 증식(for문 2씩 곱하기, P, J) (0) | 2022.12.29 |
프로그래머스 C# n의 배수 고르기(List.Add, P, J) (0) | 2022.12.29 |
프로그래머스 C# 개미 군단(나머지와 몫 활용, P, J) (0) | 2022.12.29 |
글
프로그래머스 C# 세균 증식(for문 2씩 곱하기, P, J)
using System;
public class Solution {
public int solution(int n, int t) {
for(int i=1;i<=t;i++)
{
n = 2*n;
}
return n;
}
}
파이썬
////
def solution(n, t):
answer = 2**t * n
return answer
비트연산
////
def solution(n, t):
return n << t
자바
class Solution {
public int solution(int n, int t) {
int answer = 0;
answer = n << t;
return answer;
}
}
class Solution {
public int solution(int n, int t) {
int answer = n;
for(int i=1; i<=t; i++)
{
answer *= 2;
}
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 암호 해독(주기, P, J) (0) | 2022.12.29 |
---|---|
프로그래머스 C# 대문자와 소문자(ToUpper(), ToLower()) Char.ToUpper(스트링), 스트링.ToUpper(),P,J) (0) | 2022.12.29 |
프로그래머스 C# n의 배수 고르기(List.Add, P, J) (0) | 2022.12.29 |
프로그래머스 C# 개미 군단(나머지와 몫 활용, P, J) (0) | 2022.12.29 |
프로그래머스 C# 모음 제거하기(Replace, string[] 만들고 +=, P, J) (0) | 2022.12.29 |