Palindrome(Beginner )

Dev Skill archived problems can be discussed here.

Palindrome(Beginner )

by akib9ctg » Thu Jul 21, 2016 12:35 pm

এই problem টার এই কোডটাতে কি সমস্যা হচ্ছে। যার কারনে wrong answer আস্তেছে বারবার। যদি কেও একটু বলতেন?

Beginner Beginners Problems > Ad-hoc

A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward.

We want you to write a program that can check whether a given input is palindrome or not. The input will only contain English alphabets and digits. Remember, in this task, uppercase and lowercase letter count as same.

Input:
Input starts with an integer T (≤ 30), denoting the number of test cases. Each test case will have one line containing the text to test.

Output:
For each test case, print either “Yes” (without quotes) or “No” (without quotes). If the input text is palindrome then print “Yes”, otherwise print “No”

Sample Input
3
abababa
ababab
1EYE1
Sample Output
Yes
No
Yes




CODE:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int i,c,l,t,ck,m;
string a;
scanf("%d",&t);
getchar();
for(m=1; m<=t; m++)
{
cin>>a;
ck=0;
c=a.size();
for(i=0; a[i]; i++)
{
if(isupper(a[i]))
a[i]=tolower(a[i]);

}

for(i=0,l=c-1; i<c/2; i++,l--)
{
if(a[i]==a[l] )
ck=1;
else
{
ck=0;
break;
}
}
if(ck==1)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
 
Posts: 2
Joined: Thu Jul 21, 2016 12:21 pm

Re: Palindrome(Beginner )

by devskill » Thu Jul 21, 2016 8:29 pm

Hi, first of all, please put some effort in formatting the post ;)

Code/input/output should be inside code snippet. And do not post the problem description, you can just hyper link it or name the problem number.

Anyway:

Try the following I/O

Input:
Code: Select all
2
u
1


Output:
Code: Select all
Yes
Yes
User avatar
Site Admin
 
Posts: 118
Joined: Tue Feb 02, 2016 10:24 pm

Re: Palindrome(Beginner )

by akib9ctg » Sat Jul 23, 2016 12:25 am

Thank you
 
Posts: 2
Joined: Thu Jul 21, 2016 12:21 pm

Palindrome(Beginner )

by raskin » Wed Jul 27, 2016 9:10 pm

Please help me to find out the problem as I am getting wrong answer for following C# code
-------------------------------------------------------------------------------------------------------------

Code: Select all
using System;

namespace DevSkillProblems
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] arrInput;
            int T = 3; //Convert.ToInt32(Console.ReadLine());

            if (T <= 30)
            {
                arrInput = new string[T];

                for (int i = 0; i < T; i++)
                {
                    //arr1[i] = Console.ReadLine();
                    arrInput[0] = "abababa";
                    arrInput[1] = "ababab";
                    arrInput[2] = "1EYE1";
                }

                foreach (string value in arrInput)
                {
                    Console.WriteLine(IsPalindrome(value));
                }

                //Console.ReadLine();
            }
        }

        public static string IsPalindrome(string value)
        {
            int min = 0;
            int max = value.Length - 1;
            while (true)
            {
                if (min > max)
                {
                    return "Yes";
                }
                char a = value[min];
                char b = value[max];
                if (char.ToLower(a) != char.ToLower(b))
                {
                    return "No";
                }
                min++;
                max--;
            }
        }
    }
}
 
Posts: 1
Joined: Wed Jul 27, 2016 8:56 pm

Re: Palindrome(Beginner )

by devskill » Thu Jul 28, 2016 7:00 am

It seems like the code you have posted here, you have commented out input taking and instead hard coded your input. Can you please provide your real code?

For example,
for the above test I/O in this post:

2
u
1

your output is:
Yes
No
Yes

But should be:
Yes
Yes

please read other post and check your code before you post. :)
User avatar
Site Admin
 
Posts: 118
Joined: Tue Feb 02, 2016 10:24 pm


Who is online
Users browsing this forum: No registered users and 1 guest
cron