Equidistant Characters from Start & End
Coding Problem Keys
Equidistant Characters from Start & End
Problem Statement
Given a string value S1 the program must print only the character which are present in the same position from the start of S1 as well as the end of S1 in the order of their occurrence.Boundary Condition(s)
1 <= Length of S1 <= 1000Input Format
The first line contains S1.Output Format
The first line contains the string value containing the characters which are present in the same position from the start of S1 as well as the end of S1.Example Input/Output 1
Input
engineOutput
en
Explanation
The character 'en' is present in same position from start ' engine' as well as the end 'engine' for the string 'engine'.
Example Input/Output 2
Input
malayalamOutput
malayExplanation
The characters 'malay' is present in same position from start ' malayalam' as well as the end 'malayalam' for the string 'malayalam'
Max Execution Time Limit: 5000 millisecs
Solution
Programming Language: C Language
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char str1[1001];
int i,j;
scanf("%s",str1);
int len=strlen(str1);
for(i=0,j=len-1;i<=len/2,j>=len/2;i++,j--){
if(str1[i]==str1[j]){
printf("%c",str1[i]);
}
}
}
// Published By PKJCODERS
Alter
#include<stdio.h>
#include<string.h>
int main(){
char a[1000];
int i,n,r;
scanf("%s",a);
n=strlen(a);
r=n/2;
if(n%2==1)
r+=1;
for(i=0;i<r;i++){
if(a[i]==a[n-1-i])
printf("%c",a[i]);
}
}
// Published By PKJCODERS
(Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.)
Comments