프로그래머스/C++ 조건문자열
#include #include using namespace std; int solution(string ineq, string eq, int n, int m) { int answer = 0; if(ineq == "" && eq == "!" && n>m){ answer = 1; } else answer = 0; return answer; } 이거는 다른 방법을 찾아보려했지만 블로그도 다른 방법이 없었다 조건문을 잘 쓰는것도 중요하니까 나름 코드 짜보면서 재밌었다. 간단하면서 복잡하지않은 문제였다.
2023.09.24
프로그래머스 홀짝에 따라 다른 값 변환하기 C++
#include #include using namespace std; int solution(int n) { int answer = 0; if(n%2==0){ for(int i=0; i
2023.09.23
프로그래머스 공배수 C++
#include #include using namespace std; int solution(int number, int n, int m) { int answer = 0; if(number%n==0 && number%m==0){ answer = 1; } else{ answer = 0; } return answer; }
2023.09.23
프로그래머스 n의 배수 C++
#include #include using namespace std; int solution(int num, int n) { int answer = 0; if(num%n == 0){ answer = 1; } else{ answer = 0; } return answer; } 짝수홀수 찾는 방법을 알고있다면 쉬울듯 하다.
2023.09.23
프로그래머스 두 수의 연산값 비교하기 C++
#include #include using namespace std; int solution(int a, int b) { int answer = 0; string a1 = to_string(a); string b1 = to_string(b); string a_b = a1 + b1; if(stoi(a_b)
2023.09.23
프로그래머스 더 크게 합치기 C++
#include #include using namespace std; int solution(int a, int b) { int answer = 0; string a1 = to_string(a); string b1 = to_string(b); int a1_b1 = stoi(a1+b1); int b1_a1 = stoi(b1+a1); if(a1_b1 < b1_a1) answer = b1_a1; else answer = a1_b1; return answer; } 흠..다른 방법으로 풀어볼려했지만 이 방법이 제일 나은듯하다 문자열끼리 더한후 int로 형 변환후 그 값을 비교해서 answer에 넣는것밖에는 모르겠다 ㅠㅜ
2023.09.22
프로그래머스 문자열 곱하기 C++
#include #include using namespace std; string solution(string my_string, int k) { string answer = ""; for(int i=0; i
2023.09.22
프로그래머스 문자 리스트를 문자열로 변환하기 C++
#include #include using namespace std; string solution(vector arr) { string answer = ""; for(int i=0; i
2023.09.22
반응형
#include <string>
#include <vector>

using namespace std;

int solution(string ineq, string eq, int n, int m) {
    int answer = 0;
     
    if(ineq == "<" && eq == "=" && n<=m || ineq == "<" && eq =="!" && n<m ||
        ineq == ">" && eq == "=" && n>=m || ineq == ">" && eq == "!" && n>m){
        answer = 1;
    }
    else answer = 0;
    
    return answer;
}

이거는 다른 방법을 찾아보려했지만 블로그도 다른 방법이 없었다 조건문을 잘 쓰는것도 중요하니까 나름 코드 짜보면서 재밌었다. 간단하면서 복잡하지않은 문제였다.

반응형
반응형
#include <string>
#include <vector>

using namespace std;

int solution(int n) {
    int answer = 0;
    if(n%2==0){
        for(int i=0; i<=n; i+=2){
            answer += i*i;
        }
    }
    else{
        for(int i=1; i<=n; i+=2){
            answer += i;
        }
    }
    
    return answer;
}
반응형
반응형
#include <string>
#include <vector>

using namespace std;

int solution(int number, int n, int m) {
    int answer = 0;
    
    if(number%n==0 && number%m==0){
        answer = 1;
    }
    else{
        answer = 0;
    }
    
    return answer;
}
반응형
반응형
#include <string>
#include <vector>

using namespace std;

int solution(int num, int n) {
    int answer = 0;
    if(num%n == 0){
        answer = 1;
    }
    else{
        answer = 0;
    }
    
    return answer;
}

짝수홀수 찾는 방법을 알고있다면 쉬울듯 하다.

반응형
반응형
#include <string>
#include <vector>

using namespace std;

int solution(int a, int b) {
    int answer = 0;
    string a1 = to_string(a);
    string b1 = to_string(b);
    string a_b = a1 + b1;
    
    if(stoi(a_b) <= 2*a*b ){
        answer = 2*a*b;
    }
    else{
        answer = stoi(a_b);
    }
    
    
    return answer;
}

처음 문제를 읽었을때 제대로 이해가 안됐었다..ㅋㅋㅋ 그래서 문제를 제대로 이해하고 푸는게 중요하다. 문제 출제자의 의도를 파악하고 문제를 푸는것!

반응형
반응형
#include <string>
#include <vector>

using namespace std;

int solution(int a, int b) {
    int answer = 0;
    
    string a1 = to_string(a);
    string b1 = to_string(b);
    
    int a1_b1 = stoi(a1+b1);
    int b1_a1 = stoi(b1+a1);
    
    if(a1_b1 < b1_a1) answer = b1_a1;
    else answer = a1_b1;
    
    
    
    return answer;
}

흠..다른 방법으로 풀어볼려했지만 이 방법이 제일 나은듯하다 문자열끼리 더한후 int로 형 변환후 그 값을 비교해서 answer에 넣는것밖에는 모르겠다 ㅠㅜ

반응형
반응형
#include <string>
#include <vector>

using namespace std;

string solution(string my_string, int k) {
    string answer = "";
    
    for(int i=0; i<k; i++){
        answer += my_string;
    }
    
    return answer;
}
반응형
반응형
#include <string>
#include <vector>

using namespace std;

string solution(vector<string> arr) {
    string answer = "";
    
    for(int i=0; i<arr.size(); i++){
        answer += arr[i];
    }
    
    return answer;
}
반응형