검색결과 리스트
프로그래밍에 해당되는 글 335건
- 2023.01.26 프로그래머스 C# 3진법 뒤집기(int.Parse, 3진수 표기하기)
- 2023.01.26 C# 타겟 넘버(DFS)
- 2023.01.26 C# 개인정보 수집 유효기간
- 2023.01.26 C# 기사단원의 무기(약수)
- 2023.01.25 프로그래머스 C# 스킬트리(IndexOf)
- 2023.01.25 프로그래머스 C# 예산(int[]의 Sort)
- 2023.01.25 프로그래머스 C# 최소직사각형(한 쪽으로 배열을 몰아서 비교하고 곱하기) - 완전탐색
- 2023.01.25 프로그래머스 C# 모의고사(비교대상 배열을 정의) - 완전탐색
글
프로그래머스 C# 3진법 뒤집기(int.Parse, 3진수 표기하기)
using System;
public class Solution {
public int solution(int n) {
int answer = 0;
int ans = 0;
int a = 0;
int k = 1;
string samjin = "";
while(n > 0)
{
ans = n % 3;
samjin += ans.ToString();
n = n / 3;
a++;
}
for(int i = a-1;i>=0;i--)
{
answer += k * int.Parse(samjin[i].ToString());
k = 3 * k;
}
return answer;
}
}
//하기는 했는데 변수가 너무 남발되는 거 같다. 처음부터 거꾸로 3진법을 출력하게 했으니 원래대로 3진법이 나오게 하는 방법도 찾아봐야 할 거 같다.
////
using System;
public class Solution {
public int solution(int n) {
int answer = 0;
while(n>0)
{
answer = answer * 3;
answer += n%3;
n/=3;
}
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
C# 소수 만들기(3중 for문) (0) | 2023.01.26 |
---|---|
코테 공부 순서 (0) | 2023.01.26 |
C# 타겟 넘버(DFS) (0) | 2023.01.26 |
C# 개인정보 수집 유효기간 (0) | 2023.01.26 |
C# 기사단원의 무기(약수) (0) | 2023.01.26 |
글
C# 타겟 넘버(DFS)
using System;
using System.Collections;
using System.Collections.Generic;
public class Solution
{
List<int> result;
public int solution(int[] numbers, int target)
{
int answer = 0;
result = new List<int>();
FindTarget(numbers, 0, target, 0);
for (int i = 0; i < result.Count; i++)
{
if (result[i] == target) answer++;
}
return answer;
}
public void FindTarget(int[] numbers, int index, int targetNumber, int currentValue)
{
if (index == numbers.Length)
{
result.Add(currentValue);
}
else
{
int currentValue1 = currentValue + numbers[index];
FindTarget(numbers, index + 1, targetNumber, currentValue1);
int currentValue2 = currentValue - numbers[index];
FindTarget(numbers, index + 1, targetNumber, currentValue2);
}
}
}
////
using System;
public class Solution {
static int Dfs(int[] arr, int target, int idx, int num)
{
if (idx == arr.Length)
{
if (target == num)
return 1;
else
return 0;
}
else
return Dfs(arr, target, idx + 1, num + arr[idx]) + Dfs(arr, target, idx + 1, num - arr[idx]);
}
public int solution(int[] numbers, int target) {
int answer = 0;
return Dfs(numbers, target, 0, 0);
}
}
'프로그래밍' 카테고리의 다른 글
코테 공부 순서 (0) | 2023.01.26 |
---|---|
프로그래머스 C# 3진법 뒤집기(int.Parse, 3진수 표기하기) (0) | 2023.01.26 |
C# 개인정보 수집 유효기간 (0) | 2023.01.26 |
C# 기사단원의 무기(약수) (0) | 2023.01.26 |
프로그래머스 C# 스킬트리(IndexOf) (0) | 2023.01.25 |
글
C# 개인정보 수집 유효기간
using System;
using System.Collections.Generic;
public class Solution {
public int[] solution(string today, string[] terms, string[] privacies) {
List<int> list = new List<int>();
int todayYear = int.Parse(today.Split('.')[0]);
int todayMonth = int.Parse(today.Split('.')[1]);
int todayDay = int.Parse(today.Split('.')[2]);
//.을 기준으로 나누고 int형으로 변환
int todaySum = (todayYear * 12 * 28) + (todayMonth * 28) + todayDay;
// 현재 날짜를 숫자로 표시하기
string[] termsCode = new string[terms.Length];
int[] termsMonth = new int[terms.Length];
for(int i = 0; i < terms.Length; i++)
{
termsCode[i] = terms[i].Split(' ')[0];
// 약관 종류 캐치하기
termsMonth[i] = int.Parse(terms[i].Split(' ')[1]);
// 약관이 몇 개월인지 int형으로 캐치하기
}
for(int i = 0; i < privacies.Length; i++)
{
string[] temp = privacies[i].Split('.', ' ');
// 0 년도 1 월 2 일 3 약관 기호
int year = int.Parse(temp[0]);
int month = int.Parse(temp[1]);
int day = int.Parse(temp[2]);
int num = Array.IndexOf(termsCode, temp[3]);
// 약관 기호가 termsCode 내에 있는 지에 따라 num설정
month += Convert.ToInt32(termsMonth[num]);
// 약관 기호에 적힌 달 수 만큼 플러스를 시킨다.
int sum = (year * 12 * 28) + (month* 28) + day - 1;
// 날짜 수를 체크한다.
if(todaySum > sum)
{
list.Add(i + 1);
// 배열이니까 0부터 시작해서 +1해서 리스트에 넣어주고 ToArray()한다.
}
}
int[] answer = list.ToArray();
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 3진법 뒤집기(int.Parse, 3진수 표기하기) (0) | 2023.01.26 |
---|---|
C# 타겟 넘버(DFS) (0) | 2023.01.26 |
C# 기사단원의 무기(약수) (0) | 2023.01.26 |
프로그래머스 C# 스킬트리(IndexOf) (0) | 2023.01.25 |
프로그래머스 C# 예산(int[]의 Sort) (0) | 2023.01.25 |
글
C# 기사단원의 무기(약수)
using System;
using System.Collections.Generic;
public class Solution {
public int solution(int number, int limit, int power) {
int answer = 0;
int num = 0;
int[] count = new int[number + 1];
for(int i = 1; i <= number; i++)
{
for(int j = i;j<=number;j+=i)
{
count[j]++;
}
}
for(int i = 0; i <= number; i++)
{
if(count[i] > limit)
{
answer += power;
}
else
{
answer += count[i];
}
}
return answer;
}
}
////
using System;
public class Solution {
public int solution(int number, int limit, int power) {
int answer = 0;
int anw = 0;
for(int j = 1 ;j <= number ;j++) //count is current number , number is final number
{
for(int i = 1; i <= j; i++)
{
if(i > j/2+1)
{
anw++;
break;
}
if(j % i == 0)
{
anw++;
}
}
if(anw > limit)
{
anw = power;
}
answer += anw;
anw = 0;
}
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
C# 타겟 넘버(DFS) (0) | 2023.01.26 |
---|---|
C# 개인정보 수집 유효기간 (0) | 2023.01.26 |
프로그래머스 C# 스킬트리(IndexOf) (0) | 2023.01.25 |
프로그래머스 C# 예산(int[]의 Sort) (0) | 2023.01.25 |
프로그래머스 C# 최소직사각형(한 쪽으로 배열을 몰아서 비교하고 곱하기) - 완전탐색 (0) | 2023.01.25 |
글
프로그래머스 C# 스킬트리(IndexOf)
using System;
public class Solution {
public int solution(string skill, string[] skill_trees) {
int answer = 0;
int treeLength = skill_trees.Length; // 스킬 트리 배열의 길이 취득
for(int i=0;i<treeLength;i++)
{
bool flag = true;
char[] skills = skill_trees[i].ToCharArray();
int cnt = 0;
int skillsLen = skills.Length;
for(int j=0;j<skills.Length;j++)
{
if(cnt < skill.IndexOf(skills[j]))
{
flag = false;
break;
}
else if(cnt == skill.IndexOf(skills[j]))
{
cnt++;
}
}
if(flag)
{
answer++;
}
}
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
C# 개인정보 수집 유효기간 (0) | 2023.01.26 |
---|---|
C# 기사단원의 무기(약수) (0) | 2023.01.26 |
프로그래머스 C# 예산(int[]의 Sort) (0) | 2023.01.25 |
프로그래머스 C# 최소직사각형(한 쪽으로 배열을 몰아서 비교하고 곱하기) - 완전탐색 (0) | 2023.01.25 |
프로그래머스 C# 모의고사(비교대상 배열을 정의) - 완전탐색 (0) | 2023.01.25 |
글
프로그래머스 C# 예산(int[]의 Sort)
using System;
public class Solution {
public int solution(int[] d, int budget) {
int answer = 0;
Array.Sort(d);
/// 소팅하고 마이너스
for(int i = 0;i<d.Length;i++)
{
if(budget >= d[i])
{
budget = budget - d[i];
answer++;
}
}
return answer;
}
}
// 다른 사람의 풀이를 보고 한 건데 약간 함정이 있는 게
// 이건 모든 경우에서 예산 배분이 안되는 경우가 없게 설정되어 있는 듯하다.
// 그래서 알고리즘 상으로는 budget을 계속 마이너스 시켜서 0보다 작아지면 그 때 까지 축적된 answer 값을 출력시키는 건데 만약에 예산 배분이 안되면 리턴 값이 0이 나오거나 -1이 나오거나 이런 식으로 처리해야 되는데 그런 케이스는 없는 경우인 거 같다.
'프로그래밍' 카테고리의 다른 글
C# 기사단원의 무기(약수) (0) | 2023.01.26 |
---|---|
프로그래머스 C# 스킬트리(IndexOf) (0) | 2023.01.25 |
프로그래머스 C# 최소직사각형(한 쪽으로 배열을 몰아서 비교하고 곱하기) - 완전탐색 (0) | 2023.01.25 |
프로그래머스 C# 모의고사(비교대상 배열을 정의) - 완전탐색 (0) | 2023.01.25 |
프로그래머스 C# 두 개 뽑아서 더하기(OrderBy, Distinct()) (0) | 2023.01.24 |
글
프로그래머스 C# 최소직사각형(한 쪽으로 배열을 몰아서 비교하고 곱하기) - 완전탐색
using System;
public class Solution {
public int solution(int[,] sizes) {
for(var i=0; i< sizes.GetLength(0); i++)
{
var tmp = 0;
if(sizes[i, 0] < sizes[i, 1])
{
tmp = sizes[i, 0];
sizes[i, 0] = sizes[i, 1];
sizes[i, 1] = tmp;
}
/// 두 번째 변의 길이가 더 길면 swap 해준다.
}
/// 배열 한쪽으로 사이즈 큰 거를 몰아줘야 한다.
int max1 = 0;
int max2 = 0;
for (var i = 0; i < sizes.GetLength(0); i++)
{
if (max1 < sizes[i, 0]) max1 = sizes[i, 0];
if (max2 < sizes[i, 1]) max2 = sizes[i, 1];
}
int answer = max1 * max2;
/// 거기서 큰 거를 양 배열에서 찾아서 곱하고 리턴하게 한다.
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 스킬트리(IndexOf) (0) | 2023.01.25 |
---|---|
프로그래머스 C# 예산(int[]의 Sort) (0) | 2023.01.25 |
프로그래머스 C# 모의고사(비교대상 배열을 정의) - 완전탐색 (0) | 2023.01.25 |
프로그래머스 C# 두 개 뽑아서 더하기(OrderBy, Distinct()) (0) | 2023.01.24 |
프로그래머스 C# N개의 최소공배수(메소드 활용, 유클리드 호제법, m대각선) n-m-temp (0) | 2023.01.24 |
글
프로그래머스 C# 모의고사(비교대상 배열을 정의) - 완전탐색
using System;
using System.Collections.Generic;
public class Solution {
public int[] solution(int[] answers) {
int[] answer = new int[answers.Length];
int[] one = new int[] {1,2,3,4,5};
int[] two = new int[] {2,1,2,3,2,4,2,5};
int[] three = new int[] {3,3,1,1,2,2,4,4,5,5};
int[] score = new int[3];
int max = 0;
List<int> list = new List<int>();
for(int i=0;i<answers.Length;i++)
{
if(one[i%5] == answers[i]) { score[0]++; }
if(two[i%8] == answers[i]) { score[1]++; }
if(three[i%10] == answers[i]) { score[2]++; }
}
//문제의 정답과 나머지를 비교해서 맞으면 스코어를 플러스 한다.
for (int i = 0; i < 3; i++)
{
if (max < score[i])
{
max = score[i];
}
}
// 스코어의 최댓값을 추출
for (int i = 0; i < 3; i++)
{
if (max == score[i])
{
list.Add(i + 1);
}
}
// 최댓값이 같은 게 있으면 리스트에 추가해준다.
return list.ToArray();
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 예산(int[]의 Sort) (0) | 2023.01.25 |
---|---|
프로그래머스 C# 최소직사각형(한 쪽으로 배열을 몰아서 비교하고 곱하기) - 완전탐색 (0) | 2023.01.25 |
프로그래머스 C# 두 개 뽑아서 더하기(OrderBy, Distinct()) (0) | 2023.01.24 |
프로그래머스 C# N개의 최소공배수(메소드 활용, 유클리드 호제법, m대각선) n-m-temp (0) | 2023.01.24 |
프로그래머스 레벨2 C# JadenCase(Split, ToString().ToUpper() / ToString().ToLower()) (0) | 2023.01.24 |