Accepted(AC):- CodeChef: Practical coding for everyone
Wrong one(WA):- CodeChef: Practical coding for everyone
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
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.
alnum() function returns true when character is uppercase, lowercase or digit so therefore your code also make temp false if it is a lowercase letter, therefore causing error.
Consider the test input:
1
</aA>
Thanks… Its running now
I’ve checked all the 3 conditions still I’m getting wrong ans – Here is the code –
t = int(input())
for _ in range(t):
tags = list(input())
if tags[0] != “<” or tags[1]!="/" or tags[-1]!=’>’:
print(“Error”)
else:
for i in range(2,len(tags)-1):
if tags[i].isalnum() == False:
flag = 0
break
elif tags[i].isalpha() and tags[i].isupper():
flag = 0
break
else:
flag = 1
if flag:
print(“Success”)
else:
print(“Error”)
Oh, right:
[simon@simon-laptop][06:52:31]
[~/devel/hackerrank/otherpeoples]>cat failed_test_case.txt
1
</>
[simon@simon-laptop][06:52:37]
[~/devel/hackerrank/otherpeoples]>cat failed_test_case.txt | ./sam_2909-HTMLTAGS.py
Traceback (most recent call last):
File "./sam_2909-HTMLTAGS.py", line 18, in <module>
if flag:
NameError: name 'flag' is not defined
But, I’m not getting any error when I run it on my platform as well as on codechef platform… otherwise it would have given error msg… But i’m getting WA. Also,
this test case gives output as “Error” on codechef platform as well…
Weird - something to do with the Python version, maybe.