학습(0)/C++ 문제풀이 63

프로.입문.모스부호1, istringstream객체

1. 값을 대입하기 귀찮아서 for문 돌려 입력받았다. 2. 문자열 공백 기준 자르기.istringstream#include  std::string input = "asdf sdf aa";std::istringstream iss(input);std::string word; ->입력받은 문자열을 스트림처럼 취급하여 공백을 기준으로 단어를 분리할 수 있도록 한다. while (iss >> word)->iss 에서 공백을 기준으로 단어를 하나씩 읽어와 word에 저장한다.  #include #include #include using namespace std;string solution(string letter) { istringstream streamLetter(letter); //문자열 자르기 용 ..

프로.입문.진료 순서

가변 배열에 사이즈 받는 거 어케하는지 몰라서 찾아봄. vector answer[leng] -> 컴파일 시점이라 상수 넣어야 함.vectoranswer(leng) -> 동적 할당  시간 복잡도 n제곱이라 맘에 안듦. 떠오르는 건 맵이랑 정렬. #include #include using namespace std;vector solution(vector emergency) { int leng = emergency.size(); vector answer(leng); int max = 0; int k = 0; int prioty = 0; for (int i = 0; i  gemini시간 복잡도 nlogn vector도 pair가 있었구나.rbegin() : 역순 (끝에서 시작) ..

프로그래머스.입문.외계행성 나이

1. 1 = a... 9 = i 로 대응.2. int를 받아 string 출력. #include #include using namespace std;string solution(int age) { //1. 문자열로 받는다. string str = to_string(age); string answer = ""; //2.문자로 끊어 아스키 코드로 치환하여 출력한다. (보정값: +49) for (char c : str) { answer.push_back((int)c + 49); } return answer;}  gemini숫자를 자릿수로 끊어서 + '0' => 문자로 치환생각만 하고 + '0' 기억안나서 포기했던 거였는데 역시 해보는 게 중요하다.#inc..