본문 바로가기

CPP5

49★] 프로그래머스 시저 암호 공백이면 그냥 넘어간다 소문자는 소문자에서 돌고( z -> a) 대문자는 대문자에서 돈다,( Z -> A) #include using namespace std; string solution(string s, int n) { for(int i = 0;i='a' && s[i] 122) s[i] += (n-26); else s[i] +=n; } // 대문자 else if(s[i] >= 'A' && s[i] 90){ s[i] -= 26; } } } return s; } 소문자에서 조심 아스키코드는 127까지만 있다.. ? 2020. 9. 17.
46★] 프로그래머스 같은 숫자는 싫어 #include #include using namespace std; vector solution(vector arr) { arr.erase(unique(arr.begin(), arr.end()), arr.end()); return arr; } stackoverflow.com/questions/1041620/whats-the-most-efficient-way-to-erase-duplicates-and-sort-a-vector What's the most efficient way to erase duplicates and sort a vector? I need to take a C++ vector with potentially a lot of elements, erase duplicates, and sor.. 2020. 9. 15.
19★] Leetcode 1436. Destination City 최종 목적지를 반환하는 문제. Destination City - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 양 끝점만 한번 나오고 나머지 city는 두 번씩 나오니까 한 번만 나오는 city 중에 목적지에 있는 city를 반환하는 문제. class Solution { public: string destCity(vector& paths) { // 한번나오고 뒤에 배치되어있는 문자열 반환 map words; map::iterator it; for(int i = .. 2020. 6. 30.
12] Leetcode 1486. XOR Operation in an Array 배타적 논리합, XOR 연산에 관한 문제다. XOR Operation in an Array - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 초기값만 start로 해주고 나머지는 이어서 고대로 해주면 된다. class Solution { public: int xorOperation(int n, int start) { int ans = start; for(int i = 1;i 2020. 6. 24.