Breaking

Sunday, 30 July 2017

Multi Layered Diamond Shaped Rhombus Pattern

Multi Layered Diamond Shaped Rhombus Pattern

Given an odd value of N, the program must print multi layered rhombus pattern in diamond shapes whose side contains N, N-2, ... 1 slashes respectively as shown below in the examples.
Input Format:
The first line contains N.
Output Format:
The  multi layered rhombus pattern in diamond shapes whose side contains N, N-2, ... 1 slashes respectively. Hash symbol is used as a filler for other values.
Boundary Conditions:
1 <= N <= 101 and N is odd.
Example Input/Output 1:
Input:
5
Output:
####/\####
###/##\###
##/#/\#\##
#/#/##\#\#
/#/#/\#\#\
\#\#\/#/#/
#\#\##/#/#
##\#\/#/##
###\##/###
####\/####
Example Input/Output 2:
Input:
11
Output:
##########/\##########
#########/##\#########
########/#/\#\########
#######/#/##\#\#######
######/#/#/\#\#\######
#####/#/#/##\#\#\#####
####/#/#/#/\#\#\#\####
###/#/#/#/##\#\#\#\###
##/#/#/#/#/\#\#\#\#\##
#/#/#/#/#/##\#\#\#\#\#
/#/#/#/#/#/\#\#\#\#\#\
\#\#\#\#\#\/#/#/#/#/#/
#\#\#\#\#\##/#/#/#/#/#
##\#\#\#\#\/#/#/#/#/##
###\#\#\#\##/#/#/#/###
####\#\#\#\/#/#/#/####
#####\#\#\##/#/#/#####
######\#\#\/#/#/######
#######\#\##/#/#######
########\#\/#/########
#########\##/#########
##########\/##########

Code:
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
    int n,i,j;
    cin>>n;
    int x,y,f=1,f1=1,f2=1;
    x=n-1;
    y=n;
    char  arr[n*2][n*2];
    for(i=0;i<n;i++)
    {
        for(j=0;j<n*2;j++)
        {
            if(x==j&&f==1)
                {
                    //cout<<"/";
                    arr[i][j]='/';
                    x--;
                    f=0;
                }
            else if(y==j&&f1==1)
                {
                    arr[i][j]='\\';
                    //cout<<"\\";
                        y++;
                        f1=0;
                }
                else
                    arr[i][j]='#';
                    //cout<<"#";
            if(f2==0&&f1!=0)
            if(i>1)
            {
                arr[i][j]=arr[i-2][j];
            }
            if(f==0)
                f2=0;
        }

        f=1;f1=1;f2=1;
      
          
      
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n*2;j++)
        {
            cout<<arr[i][j];
    }
    cout<<"\n";
}
for(i=n-1;i>=0;i--)
    {
        for(j=0;j<n*2;j++)
        {
            if(arr[i][j]=='#')
            cout<<"#";
            else if(arr[i][j]=='/')
                cout<<"\\";
            else
                cout<<"/";
        }
        cout<<"\n";
    }


}

Execute code Here:

4 comments:

  1. #include

    using namespace std;

    int main(int argc, char** argv)
    {
    char c[1000][1000],q,p;
    long long int n,m,i,j,k;
    cin>>n;
    for(i=0;i<2*n;i++)
    {
    for(j=0;j<2*n;j++)
    c[i][j]='#';
    }
    for(i=0;i<=n;i+=2)
    {
    c[i][n-1]='/';
    c[i][n]=92;
    }
    for(i=0;in;i++)
    {
    for(j=0;j<2*n;j++)
    {
    if(c[i][j]=92)
    {
    c[i-1][j-1]=92;
    }
    if(c[i][j]='/')
    c[i-1][j+1]='/';
    }
    }

    for(i=0;i<n*2;i++)
    {
    for(j=0;j<2*n;j++)
    cout<<c[i][j];

    cout<<endl;
    }
    }

    ReplyDelete
  2. import java.util.*;
    public class Hello {

    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String[][] matrix=new String[204][204];
    for(int i=0;i<2*n;i++)
    {
    for(int j=0;j<2*n;j++)
    {
    matrix[i][j]="#";
    }
    }

    for(int i=0;in;i--)
    {
    for(int j=0;j<2*n;j++)
    {
    if(matrix[i][j]=="\\")
    {
    matrix[i-1][j-1]="\\";

    }

    if(matrix[i][j]=="/")
    {
    matrix[i-1][j+1]="/";

    }
    }
    }


    for(int i=0;i<2*n;i++)
    {
    for(int j=0;j<2*n;j++)
    {
    System.out.print(matrix[i][j]);
    }
    System.out.println();
    }

    }
    }

    ReplyDelete
  3. Proper Java Implementation Of This Problem:
    Credits:Mr.Anonymous9896


    import java.util.*;
    public class Hello {

    public static void main(String[] args) {
    Scanner s= new Scanner(System.in);
    int num=s.nextInt();
    int x=num-1;
    int y=num;
    int f=1,f1=1,f2=1;
    String[][]str=new String[num*2][num*2];
    for(int i=0;i1)
    str[i][j]=str[i-2][j];
    }
    if(f==0)
    {
    f2=0;
    }
    }
    f=1;f1=1;f2=1;
    }
    for(int i=0;i=0;i--)
    {
    for(int j=0;j<num*2;j++)
    {
    if(str[i][j]=="#")
    System.out.print("#");
    else if(str[i][j]=="/")
    {
    System.out.print("\\");
    }
    else
    {
    System.out.print("/");
    }
    }
    System.out.println("");
    }


    }
    }

    ReplyDelete
  4. uncomplete Code!!

    ReplyDelete

Like