Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions week7/implementation/파일정리/arenran02/Main.cpp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::map<std::string, int>을 사용하여 고유한 파일 확장자를 키로, 해당 확장자를 가진 파일의 개수를 값으로 저장하는 방식으로 문제를 해결한 것이 좋다고 생각합니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <iostream>
#include <map>
#include <string>

int main() {
int N;
std::cin >> N;
std::map<std::string, int> extensionCount;

for (int i = 0; i < N; ++i) {
std::string filename;
std::cin >> filename;

size_t pos = filename.rfind('.');
if (pos != std::string::npos) {
std::string extension = filename.substr(pos + 1);
++extensionCount[extension];
}
}

for (const auto& pair : extensionCount) {
std::cout << pair.first << " " << pair.second << "\n";
}

return 0;
}