Author: Aryan KD
Tester: Aryan KD
Editorialist: Aryan KD
DIFFICULTY:
CAKEWALK, SIMPLE, EASY.
PREREQUISITES:
Math .
PROBLEM:
For given size of N print the following pattern
EXPLANATION:
for given N we have to print according to given pattern for example N=4
1
2*3
4*5*6
7*8*9*10
7*8*9*10
4*5*6
2*3
1
SOLUTIONS:
Setter's Solution
#include<bits/stdc++.h>
using namespace std;
void testcase()
{
int n,i,j,c=1;
cin>>n;
for(i=1;i<=n;i++){
for(j=1;j<=i;j++){
if(j<i){
cout<<to_string(c) +“*”;
c++;
}
else{
cout<<to_string(c);
c++;
}
}cout<<“\n”;
}
c=c-n;
for(i=n;i>=1;i–){
for(j=1;j<=i;j++){
if(j<i){
cout<<to_string(c) +“";
c++;
}
else{
cout<<to_string(c);
c++;
}
}
c= (c+1)-2i;
cout<<”\n";
}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}
Tester's Solution
#include<bits/stdc++.h>
using namespace std;
void testcase()
{
int n,i,j,c=1;
cin>>n;
for(i=1;i<=n;i++){
for(j=1;j<=i;j++){
if(j<i){
cout<<to_string(c) +“*”;
c++;
}
else{
cout<<to_string(c);
c++;
}
}cout<<“\n”;
}
c=c-n;
for(i=n;i>=1;i–){
for(j=1;j<=i;j++){
if(j<i){
cout<<to_string(c) +“";
c++;
}
else{
cout<<to_string(c);
c++;
}
}
c= (c+1)-2i;
cout<<”\n";
}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}
Editorialist's Solution
#include<bits/stdc++.h>
using namespace std;
void testcase()
{
int n,i,j,c=1;
cin>>n;
for(i=1;i<=n;i++){
for(j=1;j<=i;j++){
if(j<i){
cout<<to_string(c) +“*”;
c++;
}
else{
cout<<to_string(c);
c++;
}
}cout<<“\n”;
}
c=c-n;
for(i=n;i>=1;i–){
for(j=1;j<=i;j++){
if(j<i){
cout<<to_string(c) +“";
c++;
}
else{
cout<<to_string(c);
c++;
}
}
c= (c+1)-2i;
cout<<”\n";
}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}