본문 바로가기
프로그래머스코딩테스트연습풀이/C++

[프로그래머스/C++] 배열의 유사도

by 코코쵸마 2025. 2. 12.

문제

두 배열이 얼마나 유사한지 확인해보려고 합니다. 문자열 배열 s1과 s2가 주어질 때 같은 원소의 개수를 return하도록 solution 함수를 완성해주세요.

 

솔루션

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int solution(vector<string> s1, vector<string> s2) {
    int answer = 0;
    for(int i = 0; i < s1.size(); i++)
        for(int j = 0; j < s2.size(); j++){
            if(s1[i] == s2[j]){
                answer++;
            }
        }
    return answer;
}

 

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

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr