Pattern Practice 1

Problem description.
One participant in Aayam who likes any string S.
He decide to draw a pattern from string S. pattern size is |S| * |S|. where |S| length of string S.
eg. string is CAR then pattern will be
CAR
A A
RAC
please try to help me to find pattern.

Input

  • The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.Each testcase consists of a pattern consisting of a string S.

  • Output

    • For each test case, output containing string pattern.

    Constraints

    • 1T20
    • 1S1000

    Example

    Input:
    2
    string
    dheeraj
    Output:
    string
    t    n
    r    i
    i    r
    n    t
    gnirts
    dheeraj
    h     a
    e     r
    e     e
    r     e
    a     h
    jareehd 
     
    Solution: 

#include<stdio.h>
#include<string.h>
int main()
    {
    freopen("input.txt","r",stdin);  
    freopen("output.txt","w",stdout);
    char name[101],temp;
    int i,j,len,k,T;
    scanf("%d",&T);
    while(T--){
    printf("Enter Your name :");
    scanf("%s",name);
    len=strlen(name);
        //printf("\n %d \n",len);
        printf("%s",name);
        printf("\n");
    for(i=2;i<len;i++)
    {
    printf("%c",name[i-1]);
    for(k=1;k<len-1;k++)
    printf(" ");
    printf("%c",name[len-i]);
    printf("\n");
    }
    i=0;
    j=strlen(name)-1;
    while(i<j)
    {
    temp=name[i];
    name[i]=name[j];
    name[j]=temp;
    i++;
    j--;
    }
    if(len!=1)
    {
    printf("%s",name);
    printf("\n");
    }
        }
   return 0;  
}

Comments

Popular posts from this blog

Secure Database Connectivity in node.js with mysql

Export data from mysql db to csv file using java

API (Application Programming Interface)