백준 1141 c++ : 정렬


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
void input_data(vector<string> &str)
{
int i, N;
string temp_str;
cin >> N;
for (i = 0; i < N; i++) {
cin >> temp_str;
str.push_back(temp_str);
}
return;
}
int find_answer(vector<string>& str) {
int answer = str.size();
int i, j;
string current, compare;
sort(str.begin(), str.end());
cout << "정렬결과\n";
for (string temp : str) {
cout << temp << "\n";
}
cout << "\n";
for (i = 0; i < str.size(); i++) {
current = str[i];
for (j = i + 1; j < str.size(); j++) {
compare = str[j];
//current가 compare의 접두어인지 판단
if (compare.find(current) == 0) {
cout << current << "는 " << compare << "의 접두어임\n";
answer--;
break;
}
}
cout << "answer : " << answer << "\n";
}
return answer;
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
vector<string> str;
input_data(str);
cout << find_answer(str) << "\n";
return 0;
}