Skip to content

Instantly share code, notes, and snippets.

@nicolekorch
Created December 14, 2025 11:09
Show Gist options
  • Select an option

  • Save nicolekorch/c537f7b6715d9b70b8503a125823be50 to your computer and use it in GitHub Desktop.

Select an option

Save nicolekorch/c537f7b6715d9b70b8503a125823be50 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
#include <stack>
#include <string>
int main() {
std::string path;
std::cin >> path;
std::ifstream file(path);
if (!file.is_open()) {
std::cout << "Ошибка открытия файла";
return 0;
}
std::stack<std::string> tags;
char c;
std::string tag;
bool valid = true;
while (file.get(c)) {
if (c == '<') {
tag.clear();
file.get(c);
bool closing = false;
if (c == '/') {
closing = true;
file.get(c);
}
while (c != '>' && !file.eof()) {
tag += c;
file.get(c);
}
if (tag.empty()) continue;
if (!closing) {
tags.push(tag);
} else {
if (tags.empty() || tags.top() != tag) {
valid = false;
break;
}
tags.pop();
}
}
}
if (!tags.empty()) valid = false;
if (valid)
std::cout << "Файл валиден";
else
std::cout << "Файл не валиден";
return 0;
}
@nicolekorch
Copy link
Author

файл

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment