HTMLTAGS - Editorial

First error is that say I have a test case like this
</ > There is a space in between in that case it’ll fail. Another condition is say </> this is the case where there is nothing in it at that one also if fails.
Also group the statements
(!((s[I]>=97 && s[I]<=122) || (s[I]>=48 && s[I]<=57)))

You will have to see that its not an empty tag as well.For eg </>. This should print ‘Error’ as well.

Why getting wa ??
ll t ;
cin >> t;

while (t--) {
	string tag;
	cin >> tag;

	int s = tag.size();
	int op = tag.find_last_of("<");
	int sl = tag.find_last_of("/");
	int en = tag.find_last_of(">");
	bool ch = false ;
	nloop(i, s) {
		if (isupper(tag[i])) {
			cout << "Error" << nline;
			ch = true;
			break;
		}
	}
	if (ch == true ) continue;
	if (tag[0] == '<' && tag[1] == '/' && tag[s - 1] == '>' && op == 0 && sl == 1 && en == s - 1 && s >= 4  )
		cout << "Success" << nline;
	else
		cout << "Error" << nline;
}

Can someone please explain why is this submission(link attached) incorrect?
https://www.codechef.com/viewsolution/48200364

Consider the test input:

1
</4>

Please post your entire, formatted code, or link to your submission :slight_smile:

Edit:

I’ll make a guess - consider the test input:

1
</>>

this gives error for me:-
int n=s.size();
but when i declared n as long long it got submitted. Why n is long long? Constraint says that length(tag) is <=1000.
Can anyone explain this?

Please link to both solutions (the WA one and the AC one).

int main() {
fio;
ll t;
cin>>t;

while(t--){
 string s;
 cin>>s;
 
if(s[0]=='<' and s[1]=='/' and s[s.size() - 1]=='>' and s.size()>3){
    bool check1=1;
    for(ll i=2;i<s.size()-1;i++){
        if(!(s[i]>='a' and s[i]<='z'|| s[i]>='1' and s[i]<='9')){
        
            check1=0;
            break;
        }
        
    }
    if(check1){
        cout<<"Success" nl;
    }
    else{
        cout<<"Error" nl;
    }
}
else{
    cout<<"Error" nl;
}
 
 
}

}

Can some tell me what is wrong in this…i am getting WA.

Can anyone please explain what the error is in my code?

for _ in range(int(input())):
    tag_input = input()
    tag = list(tag_input)
    length = len(tag)
    s = True
    if length > 3 and tag[0: 2] == ['<', '/'] and tag[-1] == '>':     
        for i in range(3, length - 1):
            if '1' <= tag[i] <= '9' or 'a' <= tag[i] <= 'z':
                continue
            else:
                s = False
                break
    else:
        s = False
    if s:
        print('Success')
    else:
        print('Error')

Please post your entire, formatted code, or link to your submission :slight_smile:

Accepted(AC):- CodeChef: Practical coding for everyone

Wrong one(WA):- CodeChef: Practical coding for everyone

Thanks - the two solutions are very different - why do you assume that it is the type of n that’s causing the problem? For example, try the WA version with the test input:

1
<<4<

0 is considered as a digit so </0> is test case where ur code fails
also u should write like this (!((s[i]>=‘a’ && s[i]<=‘z’) || (s[i]>=‘0’ && s[i]<=‘9’)))

OK, got it. My bad

1 Like
2
</A>
</00>
#include <bits/stdc++.h>
using namespace std;

int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);

//#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
//#endif

    int t;
    cin >> t;
    while (t--)
    {
        string str;
        cin >> str;
        bool temp = false;

        if (str[0] == '<' && str[1] == '/' && str[str.size() - 1] == '>')
        {
            temp = true;
            for (int i = 2; i < str.size()-1; i++)
            {
                if (!isalnum(str[i]))
                {
                    temp = false;
                    break;
                    
                }
            }
        }
        if (temp)
        {
            cout << "Success" << endl;
        }
        else
        {
            cout << "Error" << endl;
        }
    }

    return 0;
}

The given test case seemed to work fine but still has not been accepted. Can somebody help me to identify the error?

bro u r pro

At line 25 you have made an error : s[3] == ‘4’ try converting it to s[i] == ‘4’ . Hope it helps. :slight_smile: