Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cassert>
- #include <string>
- #include <iostream>
- #include <iomanip>
- #include <sstream>
- #include <vector>
- #include <algorithm>
- #include <cstdio>
- using namespace std;
- struct TCar
- {
- int uroven;
- //int predek;
- int typprvku;
- string text;
- int index;
- string shape;
- //string pomoc;
- };
- class CResult
- {
- public:
- CResult(void) {vectorNr=0; urmax=0;}
- void getline1 (void);
- void print (void);
- int typ (const string s);
- void printvector (void);
- string typstr (const string buffer);
- void zacatek (void);
- private:
- vector <TCar> myvector;
- //string buffer;
- int vectorNr;
- int urmax;
- };
- void CResult::getline1 (void)
- {
- int probel=0;
- string buffer;
- char c;
- TCar x;
- char buffer1[1000];
- string buffer2;
- //string lomitko='\';
- char lomitko='\\';
- //string n="\n";
- char n='n';
- int k=0;
- string buffer3;
- //int typprvku=0;
- c = cin.get();
- while (c == ' ')
- {
- c = cin.get();
- probel++;
- }
- cin.unget();
- cin >> buffer ;
- x.typprvku = typ(buffer);
- x.shape = typstr(buffer);
- c = cin.get();
- if (c != ' ')
- cin.unget();
- if (x.typprvku == 6)
- {
- cin >> buffer2 ;
- }
- c = cin.get();
- if (c != ' ')
- cin.unget();
- getline (cin, buffer);
- if (x.typprvku == 6)
- {
- buffer3=buffer;
- buffer = buffer2 +lomitko + n + buffer3;
- }
- if (x.typprvku == 1)
- {
- for (int j=0; buffer[j] != '\0';j++)
- {
- if (buffer[j] == '=')
- {
- buffer1[k] = '\0';
- buffer2=buffer1;
- k=0;
- continue;
- }
- buffer1[k] = buffer[j];
- k++;
- }
- buffer1[k]='\0';
- buffer=buffer2 +lomitko + n +buffer1;
- }
- x.uroven = probel;
- x.text = buffer;
- x.index = vectorNr;
- if (probel > urmax)
- urmax=probel;
- myvector.push_back(x);
- vectorNr++;
- c=cin.get();
- if ( c != EOF)
- {
- cin.unget();
- getline1();
- }
- }
- int CResult::typ (const string buffer)
- {
- int typprvku=0;
- if (buffer == "#attribute")
- typprvku = 1;
- else if (buffer == "#cdata-section")
- typprvku = 2;
- else if (buffer == "#comment")
- typprvku = 3;
- else if (buffer == "#element")
- typprvku = 4;
- else if (buffer == "#entity-reference")
- typprvku = 5;
- else if (buffer == "#processing-instruction")
- typprvku = 6;
- else if (buffer == "#text")
- typprvku = 7;
- return typprvku;
- }
- string CResult::typstr (const string buffer)
- {
- string typ;
- if (buffer == "#attribute")
- typ = "diamond";
- else if (buffer == "#cdata-section")
- typ = "trapezium";
- else if (buffer == "#comment")
- typ = "note";
- else if (buffer == "#element")
- typ = "circle";
- else if (buffer == "#entity-reference")
- typ = "oval";
- else if (buffer == "#processing-instruction")
- typ = "triangle";
- else if (buffer == "#text")
- typ = "plaintext";
- return typ;
- }
- void CResult::print (void)
- {
- cout << "digraph {" << endl;
- int max=0;
- for (auto it=myvector.begin(); it != myvector.end(); it++)
- cout << it -> index << "[label=\"" << it -> text << "\",shape=" << it->shape << "]" << endl;
- // for (auto it=myvector.begin(); it != myvector.end(); it++)
- // cout << it -> index >> "->"
- //max=0;
- for (int k=0; k <= urmax ; k++ )
- {
- for (int i=0; i < vectorNr ; i++)
- {
- if (myvector[i].uroven == k)
- max=i;
- if ( myvector[i].uroven == k + 1 )
- cout << myvector[max].index << "->" << myvector[i].index << endl;
- }
- }
- cout << "}";
- }
- void CResult::printvector (void)
- {
- for (auto it=myvector.begin(); it != myvector.end(); it++)
- cout << "uroven= " << it -> uroven << " index= "
- << it -> index << " typprvku= " << it -> typprvku << " shape= "
- << it->shape << " =" << it -> text << "\n";
- cout << "urmax= " << urmax << "\n";
- }
- void CResult::zacatek (void)
- {
- TCar k;
- k.index = vectorNr;
- k.uroven = 0;
- k.shape ="house";
- k.typprvku=0;
- k.text="/";
- myvector.push_back(k);
- vectorNr++;
- }
- int main ( void )
- {
- CResult x;
- x.zacatek();
- x.getline1();
- x.print();
- return 0;
- }
- digraph {
- 0[label="/", shape=house];
- 1[label="html", shape=circle];
- 2[label="lang\nen", shape=diamond];
- 3[label="xml:lang\nen", shape=diamond];
- 4[label="xmlns\nhttp://www.w3.org/1999/xhtml", shape=diamond];
- 5[label="head", shape=circle];
- 6[label="title", shape=circle];
- 7[label="FIT CVUT", shape=plaintext];
- 8[label="body", shape=circle];
- 9[label="Markup used in this document is compatible with ", shape=plaintext];
- 10[label="b", shape=circle];
- 11[label="XHTML", shape=plaintext];
- 12[label="nbsp ", shape=oval];
- 13[label=" 1", shape=plaintext];
- 14[label=". It should not contain some characters, e.g., ", shape=plaintext];
- 15[label="editor\nemph", shape=triangle];
- 16[label="<", shape=trapezium];
- 17[label="this does not display ", shape=note];
- 18[label=".", shape=plaintext];
- 0->1;
- 1->2;
- 1->3;
- 1->4;
- 1->5;
- 1->8;
- 5->6;
- 8->9;
- 8->10;
- 8->14;
- 8->15;
- 8->16;
- 8->17;
- 8->18;
- 6->7;
- 10->11;
- 10->12;
- 10->13;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement