전체 글332 수박수박수 *수박수박수? n의 값에 따른 "수박수박수.." 출력. #include #include using namespace std; string solution(int n) { string answer = ""; for(int i = 0; i 2019. 9. 5. 소수 찾기 *소수 찾기 1부터 입력받은 숫자 n 사이에 있는 소수의 개수를 반환 #include #include using namespace std; int solution(int n) { int answer = 0; vector nums = {0,0}; for(int i = 2; i 2019. 9. 5. 문자열 다루기 기본 *문자열 다루기 기본 문자열 s의 길이가 4혹은 6이고, 숫자로만 구성돼있는지 확인 #include #include using namespace std; bool solution(string s) { for ( char c : s ) { if ( isdigit(c) == false ) return false; } if ( s.length() != 4 && s.length() != 6 ) return false; } Colored by Color Scriptercs 2019. 9. 5. 문자열 내맘대로 정렬하기 *문자열 내맘대로 정렬하기(string) 문자열 리스트 strings와 정수 n이 주어짐. 문자열의 n번째 인덱스 비교. 오름차순 정렬. 단 문자열 n번째가 같으면 전체 문자열 비교. #include #include #include using namespace std; int pos; bool compareStr(string a, string b) { if(a[pos] == b[pos]) { return a 2019. 9. 5. 같은 숫자는 싫어 *같은 숫자는 싫어 배열에 연속적으로 나타나는 숫자 하나만 남기고 제거. #include #include using namespace std; vector solution(vector arr) { vector answer; int temp = arr[0]; answer.push_back(temp); for(int i : arr) { if(i != temp) { answer.push_back(i); temp = i; } } return answer; }Colored by Color Scriptercs 2019. 9. 5. 가운데 글자 가져오기 *가운데 글자 가져오기(string) #include #include using namespace std; string solution(string s) { string answer = ""; int len = s.length(); int center = (len + (len % 2)) / 2; int pos = 2 - (len % 2); answer = s.substr(center - 1, pos); return answer; } Colored by Color Scriptercs 2019. 9. 5. 이전 1 ··· 46 47 48 49 50 51 52 ··· 56 다음