Generation

generate functionFri, 31 Mar 2023

crear un programa que desde un archivo que tiene una oración, buscar las palabras repetidas

#include <string> #include <map> #include <iostream> #include <fstream> using namespace std; int main() { ifstream archivo("text.txt"); map<string, int> palabras; string linea; while(getline(archivo, linea)){ string word; for(auto c : linea){ if(c == ' '){ palabras[word]++; word = ""; } else { word += c; } } if(word != ""){ palabras[word]++; } } for(auto par : palabras){ cout<<par.first<<" : "<<par.second<<endl; } }

Questions about programming?Chat with your personal AI assistant