Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<map>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. ifstream data;
  9. map<string, int> lic_map;
  10. string temp;
  11. string slowo_najw;
  12. int najwieksza_ilosc = 0;
  13. int ile_slow =0;
  14. int ile_parzystych = 0;
  15. int liczba = 0;
  16. int ile_palin = 0;
  17.  
  18. data.open("dane.txt");
  19.  
  20. while(data>>temp)
  21. {
  22. int j;
  23. int z;
  24. ++lic_map[temp];
  25. int pozycja = temp.length()-1;
  26. for(int i = 0 ; i<temp.length()-1;i++)
  27. {
  28. if(temp[pozycja]=='2' || temp[pozycja]=='4' || temp[pozycja]=='6' || temp[pozycja]=='A' || temp[pozycja]=='C' || temp[pozycja]=='E')
  29. {
  30. ile_parzystych++;
  31. break;
  32. }
  33.  
  34. else
  35. break;
  36. }
  37.  
  38. for(j=0,z=temp.length()-1;j<z;j++,z--)
  39. {
  40. if(temp[j]!=temp[z])
  41. break;
  42. }
  43. if(j>=z)
  44. ile_palin++;
  45.  
  46.  
  47.  
  48.  
  49.  
  50. }
  51.  
  52.  
  53. for(map<string,int>::iterator it = lic_map.begin();it != lic_map.end();++it)
  54. {
  55. if(it->second > 1 )
  56. {
  57. ile_slow++;
  58. if(it->second > najwieksza_ilosc)
  59. {
  60. najwieksza_ilosc = it->second;
  61. slowo_najw = it->first;
  62. }
  63. }
  64. }
  65.  
  66.  
  67.  
  68.  
  69.  
  70. cout<<"odpowiedzi podpunkt a) "<<endl;
  71. cout<<"Slowa wystepujace wiecej, niz raz: "<<ile_slow<<endl;
  72. cout<<"Slowo wystepujace najwieksza liczbe razy: "<<slowo_najw<<endl;
  73. cout<<"Liczba wysapien tego slowa: "<<najwieksza_ilosc<<endl<<endl;
  74. cout<<"Odpowiedz podpunkt b)"<<endl;
  75. cout<<"Liczb parzystych w pliku jest: "<<ile_parzystych<<endl<<endl;
  76. cout<<"Odpowiedz pudpunkt c)"<<endl;
  77. cout<<"Liczba palindromow w pliku: "<<ile_palin<<endl;
  78.  
  79. data.close();
  80. return 0;
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement