/* ACM-ICPC Live Archive - 2007 - Tag Checker
Copyright (C) 2009 Alessandri, Santiago
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Feel free to email me to:
san[dot]lt[dot]ss[at]gmail.com
*/
#include
#include
#include
using namespace std;
int main() {
string c;
int i;
while (1) {
getline(cin, c);
if (c == "#")
break;
deque stck;
bool cont = true;
string text = c;
while (c.find("#") == string::npos) {
getline(cin, c);
text += c;
}
i = text.find("<");
while (cont && ((size_t)i != string::npos)) {
if (((size_t)i < text.length()-2) && (text[i+1] >= 'A') && (text[i+1] <= 'Z') && (text[i+2] == '>')) {
stck.push_front(text.substr(i+1,1));
}
else {
if (((size_t)i < text.length()-3) && (text[i+1] == '/') && (text[i+2] >= 'A') && (text[i+2] <= 'Z') && (text[i+3] == '>')) {
if (stck.empty()) {
cout << "Expected # found " << text.substr(i+2, 1) << ">" << endl;
cont = false;
}
else {
string out = stck.front();
string found = text.substr(i+2,1);
stck.pop_front();
if (out != found) {
cout << "Expected " << out << "> found " << found << ">" << endl;
cont = false;
}
}
}
}
i = text.find("<", i+1);
}
if (cont) {
if (stck.size() > 0) {
cout << "Expected " << stck.front() << "> found #" << endl;
}
else {
cout << "Correctly tagged paragraph" << endl;
}
}
}
}