본문 바로가기

HOME

(207)
[백준/C++] 2822번 점수 계산 #include #include #include #include #include #include #include using namespace std; bool compare(const pair &a, const pair &b) { return a.first > b.first; } int main() { vector arr; pair temp = make_pair(0,0); int answer = 0; vector num; for(int i = 1; i > temp.first; temp.second = i; arr.push_back(temp); } sort(arr.begin(), arr.end(), compare); for(int i = 0; i < 5; i++..
[프로그래머스/C++] 가장 큰 수 #include #include #include #include #include using namespace std; bool compare(const string &a, const string &b) { return a + b > b + a; } string solution(vector numbers) { vector arr; string answer; for(int it : numbers) arr.push_back(to_string(it)); sort(arr.begin(), arr.end(), compare); for(string sit : arr) answer += sit; return answer.substr(0,2) == "00" ? "0" : answer; } 주어진 숫자를 sorting해서 ..
[Leetcode/C++] 125. Valid Palindrome class Solution { public: bool isPalindrome(string s) { string str; for(char it : s) { if(isalpha(it)) str+=tolower(it); if(isdigit(it)) str+=it; } int start = 0, end = str.length()-1; for(; start end) break; if(str[start] != str[end]) return false; } return true; } }; 가운데 문자를 기준으로 앞뒤가 같은 글자인지 확인하는 문제이다. 한국어로 치면(토마토, 기러기 ...) 문자나 숫자면 새로운 string에 넣어두고 아..
[Leetcode/C++] 412. Fizz Buzz class Solution { public: vector fizzBuzz(int n) { vector answer; for(int i = 1; i
[Leetcode/C++] 1154. Day of the Year class Solution { public: int dayOfYear(string date) { int answer = 0; int data = stoi(date.substr(5,2)) -1; int year = stoi(date.substr(0,4)); for(; data > 0; data--) { if(data == 2) { answer += 28; if(year % 400 == 0 && year % 100 ==0 && year % 4 ==0) { answer += 1; } else if(year % 100 != 0 && year % 4 == 0) answer += 1; } else if(data 7 && da..
[백준/C++] 2164번 카드2 #include #include #include using namespace std; int main() { int N, temp = 0; cin >> N; queue arr; for(int i = 0; i < N; i++) { arr.push(i+1); } while(arr.size() != 1) { arr.pop(); temp = arr.front(); arr.pop(); arr.push(temp); } cout
[백준/C++] 11866번 요세푸스 문제 0 #include #include #include #include using namespace std; int main() { int N, M; int start = 0; cin >> N >> M; vector arr(N); vector answer; for(int i = 1; i arr.size()-1) start -= (arr.size()); answer.push_back(arr[start]); arr.erase(arr.begin() + start); } for(int it : arr) { answer.push_back(it); } cout
[백준/C++] 큐 2 / queue 구현 / 시간 단축 #include #include #include using namespace std; int main(void) { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); int N, num = 0; cin >> N; string str; queue q; for (int i = 0; i > str; if (str == "pop") { if (q.empty()) cout