본문 바로가기
백준

[10546] 배부른 마라토너/ [프로그래머스] 완주하지 못한 선수

by Jcoder 2018. 9. 14.

<백준>


#include <map>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
map<string, int> m;
string str[100000];
string str1;
int main()
{
int n,i;
scanf("%d",&n);
for(i = 0; i < n; i++) cin >> str[i], m[str[i]]++;
for (i = 0; i < n - 1; i++) cin >> str1, m[str1]--;
for (i = 0; i < n; i++)
{
if (m[str[i]] == 1)
{
cout << str[i];
break;
}
}
}
<프로그래머스>





















#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
string solution(vector<string> participant, vector<string> completion)
{
map <string, int> m;
string answer = "";
int i;
for (i = 0; i < participant.size(); i++)
m[participant[i]]++;
for (i = 0; i < completion.size(); i++)
m[completion[i]]--;
for (i = 0; i < participant.size(); i++)
{
if (m[participant[i]] == 1)
answer = participant[i];
}
return answer;
}


'백준' 카테고리의 다른 글

[1015] 수열 정렬  (0) 2018.10.03
[10814] 나이순 정렬  (0) 2018.10.03
[12790] Mini Fantasy War  (0) 2018.09.10
[8741] 이진수 합  (0) 2018.09.03
[10995] 별 찍기 - 20  (0) 2018.08.29