검색결과 리스트
프로그래밍에 해당되는 글 335건
- 2023.01.21 프로그래머스 C# 가운데 글자(string 몇 번째 문자 가져오기, JAVA)
- 2023.01.21 프로그래머스 C# 평행(GetLength, Distinct, float-소수, Count, JAVA)
- 2023.01.21 프로그래머스 C# 크기가 작은 부분 문자열(long.Parse, JAVA parseLong, substring)
- 2023.01.20 프로그래머스 C# 연속된 수의 합(Array.Fill, JAVA)
- 2023.01.20 프로그래머스 C# 옹알이(1) (문자열 Replace의 활용, JAVA)
- 2023.01.20 프로그래머스 C# 등수 매기기(Linq, GetLength, Array.Fill(), JAVA)
- 2023.01.20 프로그래머스 C# 다음에 올 숫자(등차 등비 수열, JAVA)
- 2023.01.20 프로그래머스 C# 저주의 숫자 3(JAVA)
글
프로그래머스 C# 가운데 글자(string 몇 번째 문자 가져오기, JAVA)
public class Solution {
public string solution(string s) {
string answer = "";
if(s.Length%2 == 1)
{
answer = s[s.Length/2].ToString(); //홀수면 한 개
}
else
{
answer = s[s.Length/2-1].ToString() + s[s.Length/2].ToString(); // 짝수면 두 개
}
return answer;
}
}
/////
class StringExercise{
String getMiddle(String word){
int length = word.length();
int mid = length / 2;
return length%2==0 ? word.substring(mid-1, mid+1) : word.substring(mid, mid+1) ;
}
// 아래는 테스트로 출력해 보기 위한 코드입니다.
public static void main(String[] args){
StringExercise se = new StringExercise();
System.out.println(se.getMiddle("power"));
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 두 정수 사이의 합(삼항연산자, JAVA) (0) | 2023.01.21 |
---|---|
프로그래머스 C# 올바른 괄호(시간 최소화, 괄호 알고리즘, JAVA) (0) | 2023.01.21 |
프로그래머스 C# 평행(GetLength, Distinct, float-소수, Count, JAVA) (0) | 2023.01.21 |
프로그래머스 C# 크기가 작은 부분 문자열(long.Parse, JAVA parseLong, substring) (0) | 2023.01.21 |
프로그래머스 C# 연속된 수의 합(Array.Fill, JAVA) (0) | 2023.01.20 |
글
프로그래머스 C# 평행(GetLength, Distinct, float-소수, Count, JAVA)
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution
{
public int solution(int[,] dots)
{
List<float> slopes = new List<float>();
int length = dots.GetLength(0);
for (int i = 0; i < length; i++)
{
for (int j = i + 1; j < length; j++)
{
slopes.Add((dots[i, 1] - dots[j, 1]) / (float)(dots[i, 0] - dots[j, 0]));
/// 경우의 수가 length * (length -1) / 2
}
}
return slopes.Distinct().Count() == length * (length -1) / 2 ? 0 : 1;
}
}
/// Distinct로 기울기를 집어 넣은 게 중복으로 사라지게 되면, 기울기가 같은 게 있으면 1을 출력 (평행) 그렇지 않으면 0을 출력
자바
class Solution {
public int solution(int[][] dots) {
int x1 = dots[3][0];
int y1 = dots[3][1];
for (int i = 0; i < 3; i++)
{
int x2 = dots[i][0];
int y2 = dots[i][1];
int x3 = dots[(i+1)%3][0];
int y3 = dots[(i+1)%3][1];
int x4 = dots[(i+2)%3][0];
int y4 = dots[(i+2)%3][1];
if(x1 == x2 || x3 == x4)
{
if(x1 == x2 && x3 == x4)
{
return 1;
}
continue;
}
if((y2-y1)/(double)(x2-x1)==(y4-y3)/(double)(x4-x3))
{
return 1;
}
}
return 0;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 올바른 괄호(시간 최소화, 괄호 알고리즘, JAVA) (0) | 2023.01.21 |
---|---|
프로그래머스 C# 가운데 글자(string 몇 번째 문자 가져오기, JAVA) (0) | 2023.01.21 |
프로그래머스 C# 크기가 작은 부분 문자열(long.Parse, JAVA parseLong, substring) (0) | 2023.01.21 |
프로그래머스 C# 연속된 수의 합(Array.Fill, JAVA) (0) | 2023.01.20 |
프로그래머스 C# 옹알이(1) (문자열 Replace의 활용, JAVA) (0) | 2023.01.20 |
글
프로그래머스 C# 크기가 작은 부분 문자열(long.Parse, JAVA parseLong, substring)
using System;
using System.Collections.Generic;
public class Solution {
public int solution(string t, string p) {
int answer = 0;
long num = 0;
for(int i = 0; i < t.Length - p.Length + 1; i++)
{
num = long.Parse(t.Substring(i, p.Length));
//t배열의 i부터 p.Length까지의 서브스트링을 만들어서 num(long)에 저장한다.
// 그거를 t.Length - p.Length + 1까지 한다. 길이가 기니까 long.Parse로 한다.
if(num <= long.Parse(p))
{
answer++;
}
// num보다 p가 더 크면 answer를 증가시킨다.
}
return answer;
}
}
//////
class Solution {
public int solution(String t, String p) {
int answer = 0;
long ip = Long.parseLong(p);
for(int i=0;i<=t.length()-p.length();i++)
{
if(Long.parseLong(t.substring(i,i+p.length()))<=ip)
{
answer++;
}
}
return answer;
}
}
class Solution
{
public int solution(String t, String p)
{
int answer = 0;
for(int i=0; i<=t.length()-p.length(); i++)
if(Long.parseLong(t.substring(i, i+p.length())) <= Long.parseLong(p))
answer++;
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 가운데 글자(string 몇 번째 문자 가져오기, JAVA) (0) | 2023.01.21 |
---|---|
프로그래머스 C# 평행(GetLength, Distinct, float-소수, Count, JAVA) (0) | 2023.01.21 |
프로그래머스 C# 연속된 수의 합(Array.Fill, JAVA) (0) | 2023.01.20 |
프로그래머스 C# 옹알이(1) (문자열 Replace의 활용, JAVA) (0) | 2023.01.20 |
프로그래머스 C# 등수 매기기(Linq, GetLength, Array.Fill(), JAVA) (0) | 2023.01.20 |
글
프로그래머스 C# 연속된 수의 합(Array.Fill, JAVA)
using System;
public class Solution {
public int[] solution(int num, int total) {
int[] answer = new int[num];
if(num%2 != 0)
{
Array.Fill(answer, total/num-num/2); //Array.Fill(추가할 배열 명, 추가할 아이템) 맨 첫 수를 구하는 식
}
else
{
Array.Fill(answer, total/num+1-num/2); // n이 짝수일 경우에 맨 첫 수를 구하는 식
}
for(int i=1;i<num;i++)
{
answer[i]=answer[i-1]+1; //1씩 더해준다.
}
return answer;
}
}
자바
class Solution {
public int[] solution(int num, int total) {
int[] answer = new int[num];
int check = num*(num+1) / 2;
int start = (total - check) / num + 1;
for (int i = 0; i < answer.length; i++)
{
answer[i] = start + i ;
}
return answer;
}
}
class Solution {
public int[] solution(int num, int total) {
int[] answer = new int[num];
int temp = 0;
for(int i=0;i<num;i++)
{
temp+=i;
}
int value = (total-temp)/num;
for(int i=0;i<num;i++)
{
answer[i]=i+value;
}
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 평행(GetLength, Distinct, float-소수, Count, JAVA) (0) | 2023.01.21 |
---|---|
프로그래머스 C# 크기가 작은 부분 문자열(long.Parse, JAVA parseLong, substring) (0) | 2023.01.21 |
프로그래머스 C# 옹알이(1) (문자열 Replace의 활용, JAVA) (0) | 2023.01.20 |
프로그래머스 C# 등수 매기기(Linq, GetLength, Array.Fill(), JAVA) (0) | 2023.01.20 |
프로그래머스 C# 다음에 올 숫자(등차 등비 수열, JAVA) (0) | 2023.01.20 |
글
프로그래머스 C# 옹알이(1) (문자열 Replace의 활용, JAVA)
using System;
public class Solution {
public int solution(string[] babbling) {
int answer = 0;
string A = "aya";
string B = "ye";
string C = "woo";
string D = "ma";
for(int i=0;i<babbling.Length;i++)
{
babbling[i] = babbling[i].Replace(A, "v");
babbling[i] = babbling[i].Replace(B, "v");
babbling[i] = babbling[i].Replace(C, "v");
babbling[i] = babbling[i].Replace(D, "v");
string rep = babbling[i].Replace("v", string.Empty);
if(rep == string.Empty)
{
answer++;
}
}
return answer;
}
}
/// 바로 string.Empty로 하지말고 v로 했다가 empty로 하는 게 포인트이다. 근데 만약에 v가 있는 상태로 나오면 그것도 문제일 듯하다.
자바
class Solution {
public int solution(String[] babbling) {
int answer = 0;
for(int i=0; i<babbling.length; i++)
{
if(babbling[i].matches("^(aya(?!aya)|ye(?!ye)|woo(?!woo)|ma(?!ma))+$"))
{
answer++;
}
}
return answer;
}
}
lass Solution {
public int solution(String[] babbling) {
int answer = 0;
for(int i =0; i < babbling.length; i++)
{
babbling[i] = babbling[i].replace("aya", "1");
babbling[i] = babbling[i].replace("woo", "1");
babbling[i] = babbling[i].replace("ye", "1");
babbling[i] = babbling[i].replace("ma", "1");
babbling[i] = babbling[i].replace("1", "");
if(babbling[i].isEmpty())
{
answer = answer + 1;
}
}
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 크기가 작은 부분 문자열(long.Parse, JAVA parseLong, substring) (0) | 2023.01.21 |
---|---|
프로그래머스 C# 연속된 수의 합(Array.Fill, JAVA) (0) | 2023.01.20 |
프로그래머스 C# 등수 매기기(Linq, GetLength, Array.Fill(), JAVA) (0) | 2023.01.20 |
프로그래머스 C# 다음에 올 숫자(등차 등비 수열, JAVA) (0) | 2023.01.20 |
프로그래머스 C# 저주의 숫자 3(JAVA) (0) | 2023.01.20 |
글
프로그래머스 C# 등수 매기기(Linq, GetLength, Array.Fill(), JAVA)
using System;
using System.Linq;
public class Solution {
public int[] solution(int[,] score) {
int[] answer = new int[score.GetLength(0)];
Array.Fill(answer, 1);
for(int i = 0;i < score.GetLength(0);i++)
{
for(int j = 0;j < score.GetLength(0);j++)
{
if(score[i,0] + score[i,1] > score[j,0] + score[j,1])
{
answer[j]++;
}
}
}
return answer;
}
}
////
자바
import java.util.*;
class Solution {
public int[] solution(int[][] score) {
List<Integer> scoreList = new ArrayList<>();
for(int[] t : score)
{
scoreList.add(t[0] + t[1]);
}
scoreList.sort(Comparator.reverseOrder());
int[] answer = new int[score.length];
for(int i=0; i<score.length; i++)
{
answer[i] = scoreList.indexOf(score[i][0] + score[i][1])+1;
}
return answer;
}
}
class Solution {
public int[] solution(int[][] score) {
double[] map = new double[score.length];
int[] result= new int[score.length];
for (int i = 0; i <score.length ; i++)
{
map[i] = (score[i][0]+ score[i][1])/2.0;
}
for (int i = 0; i <score.length ; i++)
{
int count =0;
for (int j = 0; j <score.length ; j++)
{
if(map[i] < map[j])
{
count++;
}
}
result[i] = count+1;
}
return result;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 연속된 수의 합(Array.Fill, JAVA) (0) | 2023.01.20 |
---|---|
프로그래머스 C# 옹알이(1) (문자열 Replace의 활용, JAVA) (0) | 2023.01.20 |
프로그래머스 C# 다음에 올 숫자(등차 등비 수열, JAVA) (0) | 2023.01.20 |
프로그래머스 C# 저주의 숫자 3(JAVA) (0) | 2023.01.20 |
프로그래머스 C# 유한소수와 무한소수(2,5, JAVA) (0) | 2023.01.19 |
글
프로그래머스 C# 다음에 올 숫자(등차 등비 수열, JAVA)
using System;
public class Solution {
public int solution(int[] common) {
int answer = 0;
if(common[1]-common[0] == common[2]-common[1])
{
answer = common[common.Length-1]+common[1]-common[0];
}
else
{
answer = common[common.Length-1]*(common[1]/common[0]+common[1]%common[0]);
}
return answer;
}
}
/////
자바
class Solution {
public int solution(int[] common) {
int answer = 0;
int x = common[1] - common[0];
int y = common[2] - common[1];
if (x == y)
{
answer = common[common.length - 1] + y;
}
else
{
answer = common[common.length - 1] * common[2] / common[1];
}
return answer;
}
}
class Solution {
public int solution(int[] common) {
int answer = 0;
if(common[1] - common[0] == common[2] - common[1])
{
answer = common[common.length-1] + (common[1] - common[0]);
}
else
answer = common[common.length-1] * (common[1]/common[0]);
return answer;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 옹알이(1) (문자열 Replace의 활용, JAVA) (0) | 2023.01.20 |
---|---|
프로그래머스 C# 등수 매기기(Linq, GetLength, Array.Fill(), JAVA) (0) | 2023.01.20 |
프로그래머스 C# 저주의 숫자 3(JAVA) (0) | 2023.01.20 |
프로그래머스 C# 유한소수와 무한소수(2,5, JAVA) (0) | 2023.01.19 |
프로그래머스 C# 치킨 쿠폰(JAVA) (0) | 2023.01.19 |
글
프로그래머스 C# 저주의 숫자 3(JAVA)
using System;
public class Solution {
public int solution(int n) {
int answer = 0;
for(int i=1;i<=n;i++)
{
answer++;
if(i%3 == 0 || i%10 == 3 || (i/10)%10 == 3)
{
n++;
}
}
return answer;
}
}
자바
class Solution {
public int solution(int n) {
int answer = 0;
for (int i = 1; i <= n; i++)
{
answer++;
if (answer % 3 == 0 || String.valueOf(answer).contains("3"))
{
i--;
}
}
return answer;
}
}
class Solution {
public int solution(int n) {
String str;
for (int i = 1; i <= n; i++)
{
str = ""+i;
if(str.contains("3") || i%3 == 0)
n++;
}
return n;
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 등수 매기기(Linq, GetLength, Array.Fill(), JAVA) (0) | 2023.01.20 |
---|---|
프로그래머스 C# 다음에 올 숫자(등차 등비 수열, JAVA) (0) | 2023.01.20 |
프로그래머스 C# 유한소수와 무한소수(2,5, JAVA) (0) | 2023.01.19 |
프로그래머스 C# 치킨 쿠폰(JAVA) (0) | 2023.01.19 |
프로그래머스 C# 문자열 밀기(IndexOf, stringShift, JAVA) (0) | 2023.01.19 |