Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <string>
- #define N 1005
- using namespace std;
- string temp = "<>/", s, st[N];
- int top;
- bool check() {
- top = 0;
- for (int i = 0; i < s.size();) {
- if (s[i] != '<')
- return false;
- int j = i + 1;
- while (j < s.size() && s[j] != '>') j++;
- if (j > s.size())
- return false;
- string sub = "";
- bool close = false;
- for (int k = i + 1; k < j; k++) {
- if (s[k] == '/') {
- close = true;
- if (k != i + 1)
- return false;
- }
- else {
- sub += s[k];
- }
- }
- if (!sub.size())
- return false;
- if (close) {
- if (!top)
- return false;
- if (sub != st[top - 1])
- return false;
- top--;
- }
- else {
- st[top++] = sub;
- }
- i = j + 1;
- }
- if (!top)
- return true;
- return false;
- }
- int main() {
- freopen("xml.in", "r", stdin);
- freopen("xml.out", "w", stdout);
- cin >> s;
- for (int i = 0; i < s.size(); i++) {
- char mem = s[i];
- for (char j = 'a'; j <= 'z'; j++) {
- if (mem != j) {
- s[i] = j;
- if (check()) {
- cout << s << endl;
- return 0;
- }
- }
- }
- for (int j = 0; j < 3; j++) {
- if (mem != temp[j]) {
- s[i] = temp[j];
- if (check()) {
- cout << s << endl;
- return 0;
- }
- }
- }
- s[i] = mem;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement