본문 바로가기

c++92

[프로그래머스][C++] 바탕화면 정리 #include #include using namespace std; vector solution(vector wallpaper) { vector answer; // 모든 파일의 왼쪽 위 점의 위치를 나타냄 vector Files; for(int i = 0; i 해당 좌표를 넣음 Files.push_back({i,j}); } } } // 1. 가장 왼쪽에 있는 파일 찾기 // 2. 가장 오른쪽에 있는 파일 찾기 // 3. 가장 위쪽에 있는 파일 찾기 // 4. 가장 아래쪽에 있는 파일 찾기 int U.. 2023. 10. 20.
[C++] strchr함수 - 문자 검색 1. 라이브러리 : 2. 함수 원형 // 검색할 문자열, 존재하는지 확인할 문자(아스키 값) const char* strchr(const char* str, int c); char strchr(char* str, int c); 3. 함수 설명 - 문자열 내에서 해당 문자가 있는지 검색해주는 함수 - 첫번째 문자열 내에 두번째 문자가 존재하는지 검사 - 존재하면 존재하는 곳의 포인터 반환, 존재하지 않으면 널 포인터 반환 4. 예시 1) 특정 문자 찾기 // string 이용 -> 주소값 사용 string str = "aAbBcCdD"; char* ptr = strchr(&str[0], 'C'); // 알파벳 C를 찾음 if(ptr != nullptr) { cout 2023. 10. 20.
[프로그래머스][C++] 신규 아이디 추천 #include #include using namespace std; string solution(string new_id) { for(int i = 0; i = '0' && new_id[i] = 'a' && new_id[i] = 'A' && new_id[i] 2023. 10. 20.
[프로그래머스][C++] 배열 만들기 3 #include #include using namespace std; vector solution(vector arr, vector intervals) { vector answer; int first_begin = intervals[0][0]; int first_end = intervals[0][1]; int second_begin = intervals[1][0]; int second_end = intervals[1][1]; for(int i = first_begin; i 2023. 10. 20.
[C++] npos 1. string::npos란? - string의 find() 함수 수행 시에 찾는 문자열이 없을 때 반환된다. - '-1' 의 값을 가지는 상수이다. 2. 예시 string s = "abcde"; if(s.find('a') == string::npos) // a는 s에 들어있으므로 false 반환 { cout 2023. 10. 19.
[프로그래머스][C++] 홀짝 구분하기 #include using namespace std; int main(void) { int n; cin >> n; cout 2023. 10. 19.
[프로그래머스][C++] 둘만의 암호 #include #include #include using namespace std; string solution(string s, string skip, int index) { string answer = ""; // 해당 단어를 만났을 때 스킵할지 여부 map IsSkip; for(int i = 0; i 'z') { .. 2023. 10. 19.
[프로그래머스][C++] 문자열 돌리기 #include #include using namespace std; int main(void) { string str; cin >> str; for(int i = 0; i < str.size(); i++) { cout 2023. 10. 19.
[C++] final 키워드 1. final - 상속을 방지하는 키워드 - 더 이상 가상함수를 오버라이딩하지 않겠다는 의미 - 가상함수의 마지막을 가르키는 키워드 - 클래스와 멤버함수 둘 다 사용 가능 - override와 같은 자리에 쓰임 2. 예시 #include using namespacee std; class A { public: virtual void print() { cout 2023. 10. 18.
[프로그래머스][C++] 대충 만든 자판 #include #include #include using namespace std; vector solution(vector keymap, vector targets) { vector answer; map key; // 키맵을 돌면서 각 단어별 찾아야되는 횟수를 미리 파악 for(int i = 0; i 최소 횟수로 변경 if(key[curWord] ==.. 2023. 10. 18.
[프로그래머스][C++] 조건에 맞게 수열 변환하기 2 #include #include #include using namespace std; int solution(vector arr) { int x = 0; while(true) { vector prevArr = arr; // 이전 배열 for(int i = 0; i = 50 && arr[i] % 2 == 0) { // 50보다 크거나 같고, 짝수인 경우 arr[i] /= 2; } else if(arr[i] < 50 && arr[i] % 2 == 1) { // 50보다 작고, 홀수인 경우 arr[i] = arr[i] * 2 + 1; } } // 정렬 sort(prevArr.begin(), prevArr.end()); sort(arr.begin(), a.. 2023. 10. 18.
[프로그래머스][C++] 달리기 경주 #include #include #include using namespace std; vector solution(vector players, vector callings) { map playersRank; for(int i = 0; i < players.size(); i++) { playersRank[players[i]] = i; } for(int i = 0; i < callings.size(); i++) { // 현재 플레이어 등수 int curPlayerRank = playersRank[callings[i]]; playersRank[players[curPlayerRank]]--; // 현재 플레이어 순위 상승 playersRank[players[curPlayerRank - 1]]++; // 추월당한.. 2023. 10. 17.