알고리즘
백준 20291번 파일 정리 C++
영춘권의달인
2022. 9. 6. 20:24
map<string, int> 로 확장자의 개수를 저장하였다. map을 이용하면 자동으로 사전순으로 정렬된다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
#include <bitset>
using namespace std;
using int64 = long long;
int n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
map<string, int> m;
for (int i = 0; i < n; i++) {
string str;
cin >> str;
string extension = "";
bool found = false;
for (int j = 0; j < str.length(); j++) {
if (found) extension += str[j];
if (str[j] == '.') found = true;
}
m[extension]++;
}
for (auto a : m) {
cout << a.first << " " << a.second << "\n";
}
}