Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <cstdlib>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. struct element
  10. {
  11. string wyraz;
  12. element *next;
  13. };
  14. struct kolejka
  15. {
  16. element* head;
  17. element* tail;
  18. };
  19.  
  20. void odwracanie(string &wiadomosc);
  21. void add(string kursor,element* &stos);
  22. void deletee(element* &stos);
  23.  
  24. int main()
  25. {
  26. string wiadomosc;
  27. cout<<"Zadanie 1: "<<endl;
  28. odwracanie(wiadomosc);
  29.  
  30. return 0;
  31. }
  32. void odwracanie(string &wiadomosc)
  33. {
  34. string sciezka,kursor,znak;
  35. bool kropka;
  36. element *stos = nullptr;
  37. ifstream plik;
  38. sciezka="wiadomosc.txt";
  39. plik.open(sciezka);
  40.  
  41. while(!plik.eof())
  42. {
  43. kropka=false;
  44.  
  45. while(!kropka && !plik.eof())
  46. {
  47. getline(plik,kursor,' ');
  48.  
  49.  
  50. if(kursor.back()=='!'||kursor.back()=='?'||kursor.back()=='.')
  51. {
  52. znak=kursor.back();
  53. kropka=true;
  54. kursor.pop_back();
  55. }
  56. kursor+=" ";
  57. add(kursor,stos);
  58.  
  59. }
  60. while(stos!=nullptr)
  61. {
  62. kursor=stos -> wyraz;
  63. deletee(stos);
  64. wiadomosc=wiadomosc+kursor;
  65. }
  66. wiadomosc.pop_back();
  67. wiadomosc=wiadomosc+znak+"\n";
  68. znak=" ";
  69. }
  70. cout<<wiadomosc;
  71. }
  72. void add(string kursor,element* &stos)
  73. {
  74. element*el=new element;
  75. el->wyraz=kursor;
  76. el->next=stos;
  77. stos=el;
  78. }
  79.  
  80. void deletee(element* &stos)
  81. {
  82. element*temp=stos;
  83. stos=stos->next;
  84. delete temp;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement