Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <time.h>
- #include <fstream>
- #include <assert.h>
- #define R 4 //Rozmiar tabeli to 4
- using namespace std;
- template <typename T>
- class Element {
- public:
- T wartosc;
- Element<T> * nast;
- Element<T> * poprz;
- Element(T wartosc) {
- nast = NULL;
- this->wartosc = wartosc;
- }
- };
- bool czy_liczba(string text){
- for (int i = 0; i<text.length(); i++){
- if (!isdigit(text[i])){
- return false;
- }
- }
- return true;
- }
- template <typename T>
- class Kolejka {
- Element<T> * glowa;
- Element<T> * ogon;
- int rozmiar;
- public:
- Kolejka() {
- glowa = NULL;
- ogon = NULL;
- rozmiar = 0;
- }
- void push(T wartosc) {
- Element<T> * element = new Element<T>(wartosc);
- element->poprz = ogon;
- if (ogon) {
- ogon->nast = element;
- ogon = element;
- }
- else {
- glowa = ogon = element;
- }
- rozmiar++;
- }
- void wypisz(){
- cout << glowa->wartosc<<endl;
- }
- T pop() {
- assert(glowa);
- T wynik = glowa->wartosc;
- Element<T> * usun = glowa;
- if (glowa->nast) {
- glowa->nast->poprz = NULL;
- glowa = glowa->nast;
- if (glowa->nast == NULL){
- ogon = glowa;
- }
- }
- else {
- glowa = ogon = NULL;
- }
- delete usun;
- rozmiar--;
- return wynik;
- }
- T co_jest(){
- return ogon->wartosc;
- }
- T co_jest2(){
- return glowa->wartosc;
- }
- bool czy_istnieje(T do_sprawdzenia,T do_kad){
- Element<T> * element;
- element = ogon;
- element = element->poprz;
- while (element->poprz != NULL)
- {
- if (element->wartosc == do_kad){
- return false;
- }
- else if (element->wartosc==do_sprawdzenia)
- {
- return true;
- }
- else
- {
- element = element->poprz;
- }
- }
- return false;
- }
- bool czy_istnieje2(T do_sprawdzenia, T do_kad){
- Element<T> * element;
- element = glowa;
- element = element->nast;
- while (element->nast != NULL)
- {
- if (element->wartosc == do_kad){
- return false;
- }
- else if (element->wartosc == do_sprawdzenia)
- {
- return true;
- }
- else
- {
- element = element->nast;
- }
- }
- return false;
- }
- int size() {
- return rozmiar;
- }
- };
- int Odczyt_z_pliku(){
- ifstream in("a.txt");
- string slowo;
- string slowo2;
- string sprawdzenie;
- Kolejka<string> Stos;
- in >> slowo;
- int ktora_linijka = 0;
- if (slowo != "\\begin{enumerate}")
- {
- system("Pause");
- exit(0);
- }
- else
- {
- Stos.push(slowo);
- ktora_linijka++;
- }
- while (!in.eof()){
- sprawdzenie = Stos.co_jest() ;
- in >> slowo;
- getline(in, slowo2);
- if (slowo != "\\item" && slowo != "\\end{enumerate}"&& slowo != "\\begin{itemize}" && slowo != "\\end{itemize}"){
- cout << "wystapienie nieoczekiwanej wartości: " << slowo << endl << "linia: " << ktora_linijka << endl;
- }
- else if (slowo == "\\begin{itemize}"&&sprawdzenie != "\\item"){
- cout << "zle wpisanie wielopoziomowej listy : \\item powinno byc przed \\begin" << endl << "linia: " << ktora_linijka << endl;
- }
- else if (slowo == "\\end{itemize}"&&Stos.czy_istnieje("\\begin{itemize}", "\\end{itemize}") == false)
- {
- cout << "zle wpisanie wielopoziomowej listy : \\end{itemize} powinno byc poprzedzone \\begin" << endl<<"linia: "<<ktora_linijka<<endl;
- }
- else
- {
- Stos.push(slowo);
- }
- if (slowo == "\\end{enumerate}\r" || slowo == "\\end{enumerate}")
- {
- while (Stos.size() != 0)
- {
- Stos.co_jest2() = slowo;
- try{
- if (slowo != "\\item" && slowo != "\\end{enumerate}"&& slowo != "\\begin{itemize}" && slowo != "\\end{itemize}"){
- throw "wystapienie nieoczekiwanej wartości: " ;
- }
- else if (slowo == "\\begin{itemize}"&&sprawdzenie != "\\item"){
- throw "zle wpisanie wielopoziomowej listy : \\item powinno byc przed \\begin" ;
- }
- else if (slowo == "\\end{itemize}"&&Stos.czy_istnieje("\\begin{itemize}", "\\end{itemize}") == false)
- {
- throw "zle wpisanie wielopoziomowej listy : \\end{itemize} powinno byc poprzedzone \\begin";
- }
- else if (Stos.co_jest2() == "\\begin{itemize}"&&Stos.czy_istnieje2("\\end{itemize}", "\\begin{itemize}") == false){
- throw "zle wpisanie wielopoziomowej listy : \\begin{itemize} powinno byc zakonczone \\end" ;
- }
- }
- catch (const char * blad){
- cout << ktora_linijka - Stos.size() << ": " << blad << endl;
- }
- Stos.wypisz();
- Stos.pop();
- }
- return 0;
- }
- ktora_linijka++;
- }
- return 0;
- }
- int main(){
- Odczyt_z_pliku();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement