-
Notifications
You must be signed in to change notification settings - Fork 9
/
Pattern.c
74 lines (69 loc) · 1.12 KB
/
Pattern.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Given two strings S1 and S2, the program must print the pattern as shown in the Example Input/Output
section.
Note:
The string S1 always comes in the first row.
The string S2 is printed along the last matching column of S1.
Boundary Condition(s):
1 <= Length of S1, S2 <= 100
Input Format:
The first line contains S1.
The second line contains S2.
Output Format:
The pattern is printed as shown in the Example Input/Output section.
Example Input/Output 1:
Input:
trophy
panther
Output:
trophy
---a--
---n--
---t--
---h--
---e--
---r--
Example Input/Output 2:
Input:
morning
ninja
Output:
morning
-----i-
-----n-
-----j-
-----a-
Code:
#include<stdio.h>
#include <stdlib.h>
int main()
{
char s1[101],s2[101];
scanf("%s %s",s1,s2);
int i,l1=strlen(s1),l2=strlen(s2),r,c,p;
printf("%s\n",s1);
//GOING FROM LAST SINCE LAST OCCURING CHARACTER FROM FROWARD=FIRST OCURRING
CHARACTER IN BACKWARD
for(i=l1-1;i>=0;i--)
{
if(s2[0]==s1[i])
{
p=i;
break;
}
}
for(r=1;r<=l2-1;r++)
{
for(c=0;c<=l1-1;c++)
{
if(c!=p)
{
printf("-");
}
else
{
printf("%c",s2[r]);
}
}
printf("\n");
}
}