Monday, November 14, 2016

1225 - Palindromic Numbers (II)

Problem Link : http://lightoj.com/volume_showproblem.php?problem=1225

Solution :

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t,l,m,cnt;
    char s[20];

    scanf("%d",&t);

    for(int ca=1;ca<=t;ca++)
    {
       scanf("%s",s);
       l=strlen(s);

       if(l%2==0) m=l/2;
       else m=(l/2)+1;
       cnt =1;

       for(int i=0;i<m;i++)
       {
          if(s[i]==s[l-i-1]);
          else
          {
              cnt=0;
              break;
          }
       }

       if(cnt==0) printf("Case %d: No\n",ca);
       else printf("Case %d: Yes\n",ca);

    }
}

No comments:

Post a Comment