본문 바로가기

반복문5

[프로그래머스][C++] n 번째 원소까지 #include #include using namespace std; vector solution(vector num_list, int n) { vector answer; for(int i = 0; i < n; i++) { answer.push_back(num_list[i]); } return answer; } 1. 0부터 주어진 수 n까지 반복하며 answer에 num_list의 원소들을 넣어준다. 2. answer을 리턴한다. 이 문제를 몰라서 이 글을 볼 사람은 거의 없을 것 같다.ㅋㅋ 그 정도로 매우 쉬웠다! 2023. 10. 31.
[프로그래머스][C++] 그림 확대 #include #include using namespace std; vector solution(vector picture, int k) { vector answer; for(int i = 0; i < picture.size(); i++) { string expandStr; for(int j = 0; j < picture[i].size(); j++) { for(int n = 0; n < k; n++) { expandStr += picture[i][j]; } } for(int n = 0; n < k; n++) { answer.push_back(expandStr); } } return answer; } 1. picture의 크기만큼 반복하며 매 반복시 추가될 확장한 문자열 expandStr을 선언한다. 2.. 2023. 10. 26.
[C#][Study][기초다지기] foreach 문 foreach 문 - 배열과 같은 컬렉션의 내부에 값들을 하나씩 가져오면서 반복을 진행 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace foreach_loop { class Program { static void Main(string[] args) { string[] arr = new string[5]; // 배열 선언 // 배열의 값들을 저장 arr[0] = "Steven"; arr[1] = "Clark"; arr[2] = "Mark"; arr[3] = "Thompson"; arr[4] = "John"; // foreach문을 이용해 값을 검색 foreach (string name.. 2023. 9. 23.
[C#][Study][기초다지기] goto 문 goto 문 - label을 선언한 곳으로 돌아감 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace goto_statements { class Program { static void Main(string[] args) { string name; label: // 레이블 생성 -> 콜론 주의! Console.WriteLine("Enter your name: "); name = Console.ReadLine(); Console.WriteLine("Welcome {0}", name); Console.WriteLine("Press Ctrl + C for Exit\n"); goto label;.. 2023. 9. 23.
[백준 2798번][C++] 블랙잭 #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { int result = 0; int N, M; cin >> N >> M; if (N 100 || M 300000) return 0; vector v; for (int i = 0; i > x; if (x 100000) return 0; v.push_back(x); } int sum = 0; for (int i = 0; i < v.size() - 2; i++) { for (int j = i.. 2023. 7. 13.