GeeksforGeeks Solution For School Domain .Below You Can Find The Solution Of Basic ,Easy ,Medium ,Hard .You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers
Problem :- Given a string of a constant length, print a triangle out of it. The triangle should start with the given string and keeps shrinking downwards by removing one character from the begining of the string.
The spaces on the left side of the triangle should be replaced with dot character.
Submit Your Solution :- Click Here
Solution :-
Method 1 :-
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
int t;
cin>>t;
int i,j,k=0,temp=0;
string str;
while(t--)
{
k=0;
cin>>str;
temp=str.length();
int i=0;
do
{
cout<<str<<endl;
str[i]='.';
i++;
}while(i<temp);
}
return 0;
}
Method 2 :-
#include <iostream>
#include<cstring>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int i,j,k=0,temp=0;
string str;
cin>>str;
temp=str.length();
for(i=0;i<temp;i++)
{
for(k=0;k<i;k++)
cout<<".";
for(j=i;j<temp;j++)
cout<<str[j];
cout<<endl;
}
}
return 0;
}
Output:-
Method 1 :-
Method 2 :-
You're Welcome
ReplyDelete