전체 글 101

[프로그래머스/C++] 정수 삼각형

문제 https://school.programmers.co.kr/learn/courses/30/lessons/43105 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 설명 위와 같은 삼각형의 꼭대기에서 바닥까지 이어지는 경로 중, 거쳐간 숫자의 합이 가장 큰 경우를 찾아보려고 합니다. 아래 칸으로 이동할 때는 대각선 방향으로 한 칸 오른쪽 또는 왼쪽으로만 이동 가능합니다. 예를 들어 3에서는 그 아래칸의 8 또는 1로만 이동이 가능합니다. 삼각형의 정보가 담긴 배열 triangle이 매개변수로 주어질 때, 거쳐간 숫자의 최댓값을 return 하도록 ..

[프로그래머스/C++] 구명보트

문제 https://school.programmers.co.kr/learn/courses/30/lessons/42885 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 #include #include #include using namespace std; bool safe[500000]; int solution(vector people, int limit) { int answer = 0; sort(people.begin(), people.end(), greater()); int idx = people.size()-1; for(int i=0;i 남은 사람..

[프로그래머스/C#] 최대공약수와 최소공배

문제 https://school.programmers.co.kr/learn/courses/30/lessons/12940 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 public class Solution { public int[] solution(int n, int m) { int[] answer = new int[2]; for(int i=1;i자연수))%m==0이 나오는 수를 대입하고 break ↳최소공배수는 n과 m의 배수이므로 반대로 그 수를 n혹은 m으로 나눴을 때 0이어야 하니까 n의 배수를 m으로 나눴을 때 나머지가 0이면 된다는 생각에..

[프로그래머스/C#] 문자열 나누기

문제 https://school.programmers.co.kr/learn/courses/30/lessons/140108 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 using System; public class Solution { public int solution(string s) { int answer = 0; int cnt = 0; char c = '1'; for(int i=0;i 0) { if(first == s[0]) cnt1++; else cnt2++; s = s.Remove(0,1); if(cnt1 == cnt2) { answer+..

[프로그래머스/C#] 서울에서 김서방 찾기

문제 https://school.programmers.co.kr/learn/courses/30/lessons/12919?language=csharp 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 public class Solution { public string solution(string[] seoul) { string answer = "김서방은 {0}에 있다"; for(int i=0;ii=="Kim"): 요소중에 "Kim"과 일치하는 요소의 index 반환.

[프로그래머스/C++, C#] 두 원 사이의 정수 쌍

문제 https://school.programmers.co.kr/learn/courses/30/lessons/181187 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 -C++ #include #include #include using namespace std; long long solution(int r1, int r2) { long long answer = 0; for(int i=0;i=i) y1 = (long long)ceil(sqrt(pow(r1, 2)-pow(i, 2))); else y1 = 0; long long y2 = (long lon..

[프로그래머스/C++, C#] 달리기 경주

https://school.programmers.co.kr/learn/courses/30/lessons/178871 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 -C++ #include #include #include using namespace std; vector solution(vector players, vector callings) { //vector answer; map m; for(int i=0;i

[프로그래머스/C++] 광물 캐기

문제 https://school.programmers.co.kr/learn/courses/30/lessons/172927 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 #include #include #include using namespace std; int answer = 1500; int cal(string mineral, int type, int value){ if(mineral=="diamond"){ if(type==0) value++; else if(type==1) value+=5; else value+=25; } else if(miner..

[프로그래머스/C++] 산 모양 타일

문제 https://school.programmers.co.kr/learn/courses/30/lessons/258705?language=cpp 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 #include #include #define mod 10007 using namespace std; int solution(int n, vector tops) { int answer = 0; long long dp[100001][2]={{1,0}}; for(int i=1;i=2&&tops[i-2]==1) dp[i][1]+=dp[i-2][0]+dp[i-2][1]..

[프로그래머스/C++, C#] 네트워크

문제 https://school.programmers.co.kr/learn/courses/30/lessons/43162 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 1)BFS - C++ #include #include #include using namespace std; bool visited[200]; int solution(int n, vector computers) { int answer = 0; for(int i=0;i