본문 바로가기

분류 전체보기

(454)
[Level 1][C++] 시저 암호 #include #include #include using namespace std;string solution(string s, int n) { char* arr = new char[s.length() + 1]; strcpy(arr, s.c_str()); for (int i = 0; i = 'A' && arr[i] 'Z') arr[i] -= ('Z'-'A'+1); arr[i] += n; } else { if (arr[i]+n > 'z') arr[i] -=..
[Level 1][C++] 문자열 내림차순으로 배치하기 풀이1#include #include #include using namespace std;string solution(string s) { char * arr = new char[s.length()+1]; strcpy(arr, s.c_str()); for(int i=0; i  풀이2#include #include #include using namespace std;string solution(string s) { sort(s.begin(), s.end(), greater()); return s;} sort함수3번째 인자를 넣지 않으면 default로 오름차순으로 정렬한다. 반환형은 void.- sort(arr, arr+n)- sort(arr.begin..
[Level 1][C++] 서울에서 김서방 찾기 #include #include using namespace std;string solution(vector seoul) { int idx; for(int i=0; i
[Level 1][C++] 수박수박수박수박수박수? #include #include using namespace std;string solution(int n) { string answer = ""; for(int i=0; i
[Level 1][C++] 나누어 떨어지는 숫자 배열 #include #include using namespace std;vector solution(vector arr, int divisor) { vector answer; for(int i=0; ianswer[i+j]) { int temp = answer[i]; answer[i] = answer[i+j]; answer[i+j] = temp; } } return answer;}
[Level 1][C++] 문자열 내 p와 y의 개수 #include #include #include using namespace std;bool solution(string s){ char* arr = new char[s.length()+1]; strcpy_s(arr, s.length()+1, s.c_str()); int countP = 0; int countY = 0; for (int i = 0; i
[Level 1][C++] 문자열을 정수로 바꾸기 #include #include using namespace std;int solution(string s) { int answer = 0; answer = stoi(s); //String을 정수로 바꿔준다. Atoi는 char 배열을 정수로 바꿔준다. return answer;}
[Level 1][C++] 짝수와 홀수 #include #include using namespace std;string solution(int num) { string answer = ""; if(num%2 ==0) answer = "Even"; else answer = "Odd"; return answer;}
[Level 1][C++] 예산 #include #include #include #include #include using namespace std;vector sort(vector arr){ for (int i = 0; i arr[i + j]) { int temp = arr[i]; arr[i] = arr[i + j]; arr[i + j] = temp; } return arr;}int solution(vector d, int budget) { vector arr1; vector arr2; int average = accumulate(d.begin()..
[Level 1][C++] 평균 구하기 #include #include #include using namespace std;double solution(vector arr) { double answer = accumulate(arr.begin(), arr.end(), 0); return answer/arr.size();}