반응형
1번/ 문자출력
#include <iostream>
using namespace std;
int main(void) {
string message = "Let's go!";
cout << "3\n"<<"2\n"<<"1" << endl;
cout << message << endl;
return 0;
}
줄바꿈을 해야해서 \n을 넣어서 출력했다 중간에 << 계속 안해도 되긴하고 endl을 사용해서 줄바꿈을 해도 될듯
2번/각도 합치기
#include <iostream>
using namespace std;
int main(void) {
int angle1;
int angle2;
cin >> angle1 >> angle2;
int sum_angle = (angle1 + angle2)%360;
cout << sum_angle << endl;
return 0;
}
mod 360연산이 필요해서 나머지 연산을 넣어서 했다.
3번/ 수 나누기
#include <iostream>
using namespace std;
int main(void) {
int number;
cin >> number;
int answer = 0;
while(number>0){
answer += number % 100;
number /= 100;
}
cout << answer << endl;
return 0;
}
주어진 숫자를 나눈 몫이 0이상일 때는 두자리 수 이상의 숫자이기 때문에 연산을 계속해서 하도록 while문을 작성했다.
4번/ 병과분류
#include <iostream>
using namespace std;
int main(void) {
string code;
cin >> code;
string last_four_words = code.substr(code.size()-4, 4);
if(last_four_words == "_eye"){
cout << "Ophthalmologyc";
}
else if(last_four_words == "head"){
cout << "Neurosurgery";
}
else if(last_four_words == "infl"){
cout << "Orthopedics";
}
else if (last_four_words == "skin"){
cout << "Dermatology";
}
else{
cout << "direct recommendation";
}
return 0;
}
조건 분기문 사용해서 작성하면 댐..
5번/심폐소생
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<string> cpr) {
vector<int> answer = {0, 0, 0, 0, 0};
vector<string> basic_order = {"check", "call", "pressure", "respiration", "repeat"};
for(int i=0; i<5; i++){
for(int j=0; j<5; j++){
if(cpr[i] == basic_order[j]){
answer[i] = j+1;
break;
}
}
}
return answer;
}
size함수가 생각 안나서 i랑 j 제한을 직접 숫자로 설정했는데 저 부분은 cpr.size()랑 basic_order.size()로 변경해도 결과는 같게 나온다.
반응형
'코딩해요 > C++' 카테고리의 다른 글
[프로그래머스] PCCE 기출, 특수문자 출력 (0) | 2024.11.12 |
---|---|
[프로그래머스/C++] PCCE 기출문제 1-5번 (0) | 2024.08.27 |
[코드업/C++] 기초-조건/선택실행구조[1065 ~ 1071] (1) | 2024.01.30 |
[코드업/C++] 기초-산술연산/1039 ~ 1046 (0) | 2023.10.07 |
[코드업/C++] 기초-입출력 풀이 (0) | 2023.09.25 |