Character Patterns (Act 2) Editorial Spoj - Pattern Printing Example - UCS - Unleash-Coding-Skills

Thursday, 10 May 2018

Character Patterns (Act 2) Editorial Spoj - Pattern Printing Example - UCS


                                    Character Patterns (Act 2)

This is editorial for Character Patterns (Act 2) problem in SPOJ and the link for the problem is:

http://www.spoj.com/problems/CPTTRN2/

Be careful about output printing format there is a blank line between test cases.

The solution for this is written in python:

r = int(input())
for i in range(0,r):
    line =list(map(int,input().strip().split(' ')))
    a=line[0]
    b=line[1]
    for i in range(0,a):
        for j in range(0,b):
            if i ==0 or i==a-1:
                if j!=b-1:
                    print('*', end='')
                else :
                    print('*')
            else :
                if j==0 or j==b-1:
                    if j==b-1:
                        print('*')
                    else:
                        print('*',end='')
                else:
                    print('.',end='')
    print()

           

Input:
3
3 1
4 4
2 5

Output:
*
*
*

****
*..*
*..*
****


*****
*****

 Character Patterns (Act 2)

No comments:

Post a comment