본문 바로가기
프로그래밍/코딩테스트

[프로그래머스] 1레벨 문제

by Nessie! 2023. 6. 21.

행렬의 덧셈

https://school.programmers.co.kr/learn/courses/30/lessons/12950

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

#include <string>
#include <vector>

using namespace std;

vector<vector<int>> solution(vector<vector<int>> arr1, vector<vector<int>> arr2) 
{
    vector<vector<int>> answer;
    
    answer.reserve(arr1.size());
    
    for(int i = 0; i < arr1.size(); ++i)
    {
        vector<int> tempArr;
        tempArr.reserve(arr1[i].size());
        
        for(int j = 0; j < arr1[i].size(); ++j)
        {
            tempArr.push_back(arr1[i][j] + arr2[i][j]);
        }
        
        answer.push_back(tempArr);
    }
    
    
    return answer;
}

 

하샤드 수

https://school.programmers.co.kr/learn/courses/30/lessons/12947

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

#include <string>
#include <vector>

using namespace std;

bool solution(int x) 
{
    string strText = to_string(x);
    
    int iNum(0);
    for(int i = 0; i < strText.size(); ++i)
    {
        iNum += strText[i] - 48;
    }
    
    if(x % iNum == 0)
    {
        return true;
    }
    
    return false;
}

댓글