기본 콘텐츠로 건너뛰기

11월, 2019의 게시물 표시

프로그래머스 - 전화번호 목록

#include <string> #include <vector> #include <algorithm> using namespace std ; bool solution ( vector < string > phone_book ) { sort ( phone_book . begin (), phone_book . end ()); vector < string >:: iterator it ; for ( it = phone_book . begin (); it != phone_book . end (); ++ it ) { vector < string >:: iterator it2 = it ; for ( ++ it2 ; it2 != phone_book . end (); ++ it2 ) { if (( * it2 ). find (( * it ). c_str (), 0 , ( * it ). size ()) != string :: npos ) { return false ; } } } return true ; }

프로그래머스 - 완주하지 못한 선수

#include <string> #include <vector> #include <map> using namespace std ; string solution ( vector < string > participant , vector < string > completion ) { map < string , int > input ; map < string , int >:: iterator mit ; vector < string >:: iterator it ; for ( it = participant . begin (); it != participant . end (); ++ it ) { input [ * it ] ++ ; } for ( it = completion . begin (); it != completion . end (); ++ it ) { input [ * it ] -- ; } string answer = "" ; for ( mit = input . begin (); mit != input . end (); ++ mit ) { if ( mit -> second == 1 ) { answer = mit -> first ; break ; } } return answer ; }