Answer to Question #44993 in C for Palak

Question #44993
A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindromes with minimum number of character replacements. Input Format: First line starts with T, which is the number of test cases. Each test case contains a string (S). Output Format: For each test case print the minimum number of character replacements needed to convert the given string to palindrome. Constraints: 1<=T<=100 1<=|S|<=60, S will contains only lower case alphabets ('a'-'z') Sample Input and Output SNo. Input Output 1 2 saarj saaaa 2 1 Explanation: For case 1, among many possibilities one is to replace 4-th character with 'a' and replace last character with 's'. For case 2, among many possibilities one is to replace first character with 'a' to make it a palindrome.
Expert's answer
//Answer on Question#44993 - Progamming - C
#include <stdio.h>
#include <string.h>
int main() {
int T;
char S[70];
int len, ans, i;
scanf("%d", &T);
while (T-- > 0) {
scanf("%s", S);
len = strlen(S);
ans = 0;
for (i = 0; i < len / 2; ++i) {
if (S[i] != S[len - 1 - i]) ++ans;
printf("%d\n", ans);

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

New on Blog