There must be some issue with the test cases.
I think there is a non-lowercase english alphabet somewhere (the question specifies only lowercase english alphabets are in the input)
I Could’t understand that what’s the error in this code.
If I Put Mannual Input in this code. Its Execute sucessfully and shows the correct output. but when i submitted , this is showing wrong answer.
What should i do?
I have tried different approach . I divide the string into two and add ASCII of both strings. C1 for left ASCII and C2 for right ASCII. if both are same then they are lapindrome. My code passes the test cases But still i am getting wrong answer. Somebody help.
#include
using namespace std;
int islapin(string s){
int len=s.length();
int c1=0,c2=0,l;
bool r=true;
if(len%2 !=0){
r=false;
}
l=len/2;
for(int i=0;i<len;i++){
if(i<l){
c1+=(int)s[i];
}else if(i==l && r==false){
continue;
}else{
c2+=(int)s[i];
}
}
if(c1!=c2){
return 1;
}else{
return 0;
}
}
int main(){
int n;
cin>>n;
int a=(int)calloc(n,sizeof(int));
string s;
Thanks. But I solved it. actually this code adds the ascii values, so on input “Abab” it will print “NO”.This was getting logical errors in some cases. I changed my approach and it was accepted successfully.
This is my code and I tried many test cases and they all are correct but when I submit my code it shows WA.
/* package codechef; // don’t place package name! */
import java.util.;
import java.lang.;
import java.io.;
/ Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
int t;
Scanner scan = new Scanner(System.in);
t=scan.nextInt();
while(t>0){
String st=new String();
String b=new String();
String a= new String();
st=scan.next();
int l=0;
l=st.length();
int n1=0,n2=0;
int c=0;
if (l%2==1){
l=l/2 + 1;
for (int i=l-1;i<st.length() ;i++ ) {
b=b+st.charAt(i) ;
}
// System.out.println(b);
}
else{
l=l/2;
for (int i=l;i<st.length() ;i++ ) {
b=b+st.charAt(i) ;
}
}
for (int i=0;i<l ;i++ ) {
a=a+st.charAt(i) ;
}
for (int i=0;i<a.length() ;i++ ) {
n1=(int)(char)a.charAt(i);
n2=(int)(char)b.charAt(i);
c= n1^n2^c ;
}
// System.out.println(a+" "+b);
if (c==0){
System.out.println("YES");
}else{
System.out.println("NO");}
t-=1;
}
}
try:
for i in range(int(input())):
a = input()
n = len(a)
l = {}
m={}
if n % 2 == 0:
b = a[:n // 2]
c = a[n // 2:]
if n % 2 != 0:
b = a[:(n - 1) // 2]
c = a[(n + 1) // 2:]
for i in b:
d=b.count(i)
l[i]=d
for i in c :
e=c.count(i)
m[i]=e
if l==m:
print("YES")
else:
print("NO")
Can anyone tell what’s wrong with this code, it passes all sample testcases.
a =int(input())
def solve(z):
t = []
v = []
z = list(z)
flag = 0
if len(z) & 1!=0:
flag = 1
if flag == 1:
#odd
mid = len(z)//2
t += z[:mid]
v += z[mid+1:]
else:
mid = len(z)//2
t+=z[:mid]
v += z[mid:]
T,V = Counter(t),Counter(v)
# print(T,V)
if len(T) != len(V):
return print('No')
for i,j in T.items():
if i in V and j == V[i]:
pass
else:
return print('No')
return print('Yes')
for i in range(a):
z = input()
solve(z)