Retoorii fixes.

This commit is contained in:
retoor 2025-03-20 22:23:41 +01:00
parent 1fb6481f2b
commit ce4997317a

View File

@ -1,4 +1,12 @@
import std;
#include <vector>
#include <string>
#include <string_view>
#include <fstream>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <execution>
#include <format>
const std::vector<std::wstring_view> BAD_WORDS = {
L"recovery",
@ -38,7 +46,6 @@ const std::vector<std::wstring_view> BAD_WORDS = {
L"funds",
};
struct AnalysisResult {
std::size_t totalWordCount = 0;
std::size_t totalCapitalizedCount = 0;
@ -64,6 +71,16 @@ struct AnalysisResult {
}
};
// Overloaded operator<< for AnalysisResult
std::ostream& operator<<(std::ostream& os, const AnalysisResult& result) {
os << "Word Count: " << result.totalWordCount << "\n"
<< "Capitalized Count: " << result.totalCapitalizedCount << "\n"
<< "Sentence Count: " << result.totalSentenceCount << "\n"
<< "Number Count: " << result.totalNumberCount << "\n"
<< "Forbidden Count: " << result.totalForbiddenCount;
return os;
}
void check_word(const std::wstring &word, std::size_t &forbiddenCount) {
if (std::find(BAD_WORDS.begin(), BAD_WORDS.end(), word) != BAD_WORDS.end()) {
forbiddenCount++;
@ -73,9 +90,9 @@ void check_word(const std::wstring &word, std::size_t &forbiddenCount) {
AnalysisResult parseFile(const std::string_view &filename) {
std::wifstream file;
file.open(filename);
file.open(std::string(filename)); // Modified line
if (!file.is_open()) {
std::println("File doesn't exist: {}", filename);
std::cout << "File doesn't exist: " << filename << std::endl;
return { };
}
@ -127,7 +144,7 @@ AnalysisResult parseFile(const std::string_view &filename) {
int main(const int argc, char *argv[]) {
if (argc < 2) {
std::println("Usage: {} <file1> <file2> ... <fileN>", argv[0]);
std::cout << "Usage: " << argv[0] << " <file1> <file2> ... <fileN>" << std::endl;
return 1;
}
@ -135,6 +152,6 @@ int main(const int argc, char *argv[]) {
parseFile
);
std::println("{}", std::string(result));
std::cout << result << std::endl; // This will now work
return 0;
}
}