분류 전체보기 (452) 썸네일형 리스트형 [Level 1][C++] 약수의 합 #include #include using namespace std;int solution(int n) { int answer = 0; for(int i=1; i [Level 1][C++] 콜라츠 추측 #include #include using namespace std;int solution(int num) {int count = 0;while (num != 1){ num = (num%2 ==0)? num/2:(num*3+1); count++;if (count == 483) //테스트 케이스가 오류났다. 500이 아니라 483으로 하면 풀린다.return -1;}return count;} [Level 1][C++] 정수 내림차순으로 배치하기 #include #include #include using namespace std;long long solution(long long n) { string s = to_string(n); //long long을 string으로 변환 sort(s.begin(), s.end(), greater()); //내림차순으로 정리 long long answer = atoll(s.c_str()); //string을 long long 형으로 바꾸는 것. int형으론 atoi return answer;} [Level 1][C++] 제일 작은 수 제거하기 #include #include #include using namespace std;vector solution(vector arr) { if(arr.size() == 1) { arr[0] = -1; return arr; } int minNum = *min_element(arr.begin(), arr.end()); //min_element함수는 벡터에서 최솟값(주소값)을 찾아준다. vector answer; for(int i=0; i [Level 1][C++] 하샤드 수 #include #include using namespace std;bool solution(int x) { if(x [Level 1][C++] 핸드폰 번호 가리기 #include #include using namespace std;string solution(string phone_number) { string answer = ""; int idx=0; for(idx=0; idx [Level 1][C++] 직사각형 별찍기 #include using namespace std;int main(void) { int a; int b; cin >> a >> b; for(int m=0; m [Level 1][C++] x만큼 간격이 있는 n개의 숫자 #include #include using namespace std;vector solution(int x, int n) { vector answer; for(int i=1; i [Level 1][C++] 행렬의 덧셈 #include #include using namespace std;vector> solution(vector> arr1, vector> arr2) { vector> answer(arr1); for(int i=0; i [Level 1][C++] 가운데 글자 가져오기 #include #include using namespace std;string solution(string s) { string answer = ""; if(s.length()%2==0) answer += s.at(s.length()/2-1); // at 함수. 문자열 내 특정 위치에 있는 문자를 반환한다. answer += s.at(s.length()/2); return answer;} 이전 1 2 3 4 5 6 7 8 ··· 46 다음