Guest User

Untitled

a guest
Jan 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include<string.h>
  5. using namespace std;
  6.  
  7. struct cuvinte{
  8. char *cuvant;
  9. int numar;
  10. };
  11.  
  12. int main()
  13. {
  14. cuvinte multime[100];
  15. ifstream f;
  16. f.open("input.txt");
  17. string str;
  18. while(getline(f,str))
  19. {
  20. char * cuvant = new char[str.size() + 1];
  21. char * abc = new char[str.size() + 1];
  22. copy(str.begin(), str.end(), abc);
  23. cuvant = strtok (abc," ,/_");
  24. while(cuvant!=NULL)
  25. {
  26. for(int i=0;i<10;i++)
  27. {
  28. cout<<cuvant;
  29. if(strcmp(cuvant,multime[i].cuvant)==0)
  30. multime[i].numar++;
  31. else
  32. {
  33. for(int j=0;j<10;j++)
  34. if(multime[j].numar==0)
  35. {
  36. multime[j].cuvant=cuvant;
  37. multime[j].numar=1;
  38. }
  39. }
  40. }
  41. cuvant = strtok ( NULL , " ");
  42. }
  43. }
  44.  
  45. return 0;
  46. }
  47.  
  48. #include <string>
  49. #include <fstream>
  50. #include <unordered_map>
  51.  
  52. using WordFrequency = std::unordered_map<std::string, unsigned>;
  53.  
  54. WordFrequency read_words(std::istream& s) {
  55. WordFrequency wf;
  56. for(std::string word; s >> word;)
  57. ++wf[word];
  58. return wf;
  59. }
  60.  
  61. int main() {
  62. std::fstream f("input.txt");
  63. auto wf = read_words(f);
  64. }
Add Comment
Please, Sign In to add comment