all AI news
File Question - C++
May 7, 2024, 3:18 p.m. | FatimaAlam1234
DEV Community dev.to
Given a text file with conversation write an algorithm which can give you list of user who chat the most
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <vector>
std::vector<std::string> getMostActiveUsers(const std::string& filePath) {
std::unordered_map<std::string, int> userCounts;
// Open the file
std::ifstream file(filePath);
if (!file.is_open()) {
std::cerr << "Error: Unable to open file." << std::endl;
return {};
}
// Read the file line by line
std::string line;
while (std::getline(file, line)) {
// Extract user information
std::string username …
algorithm chat conversation error file list question string text vector
More from dev.to / DEV Community
Jobs in AI, ML, Big Data
Software Engineer for AI Training Data (School Specific)
@ G2i Inc | Remote
Software Engineer for AI Training Data (Python)
@ G2i Inc | Remote
Software Engineer for AI Training Data (Tier 2)
@ G2i Inc | Remote
Data Engineer
@ Lemon.io | Remote: Europe, LATAM, Canada, UK, Asia, Oceania
Artificial Intelligence – Bioinformatic Expert
@ University of Texas Medical Branch | Galveston, TX
Lead Developer (AI)
@ Cere Network | San Francisco, US