Skill Rack
Daily Challenge Solution
Date : 27/03/2019
Program ID- 8450
String Pattern - Alphabet Position
The program must accept a string S as the input. The program must print the desired pattern as shown in the Example Input/Output section.
Note: All the alphabets in S are only in lower case.
Boundary Condition(s):
1 <= Length of S <= 1000
Input Format:
The first line contains the string S.
Output Format:
The list of lines containing the desired pattern as shown in the Example Input/Output section.
Example Input/Output 1
Input:
abcdacg
Output:
a
bb
ccc
dddd
a
ccc
ggggggg
Example Input/Output 2:
Input:
skillrack
Output:
sssssssssssssssssss
kkkkkkkkkkk
iiiiiiiii
llllllllllll
llllllllllll
rrrrrrrrrrrrrrrrrr
a
ccc
kkkkkkkkkkk
Solution:
*******************************************************************************
#include <stdio.h>
int main()
{
char s[1000],a[26];
int i,j,k,l=0;
scanf("%s",s);
for(i='a';i<='z';i++)
{
a[l]=i;
l++;
}
for(i=0;s[i]!=NULL;i++)
{
for(j=0;j<26;j++)
{
if(s[i]==a[j])
{
for(k=0;k<=j;k++)
{
printf("%c",s[i]);
}
}
}
printf("\n");
}
return 0;
}
******************************************************************************
No comments:
Post a Comment