Created
December 14, 2025 11:09
-
-
Save nicolekorch/c537f7b6715d9b70b8503a125823be50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
файл