Coding
  • Welcome
  • Baisc Knowledge
    • Vim
    • C
      • Library
    • Java
      • Setup
      • Java Basic
  • Kattis
    • Easy
      • A Second Opinion
      • A Shortcut to What?
      • A Stack of Gold
      • ACM Contest Scoring
      • ASCII kassi
      • Aaah!
      • Add Two Numbers
      • Adding Trouble
      • Afjörmun
      • Airfare Grants
      • Above Average
      • Akcija
      • Alphabet Spam
      • Amerískur vinnustaður
      • Anti-Palindrome
      • Apaxiaaaaaaaaaaaans!
      • Arithmetic Functions
      • Arm Coordination
      • Arrangement
      • Attendance
      • Autori
      • Average Character
      • Avion
      • Baby Bites
      • Babylonian Numbers
      • ABC
      • Aldur
      • Backspace
      • Bannorð
      • Barcelona
      • Basketball One-on-One
      • Batter Up
      • Beavergnaw
      • Bela
      • BergMál
      • Bergur*
      • Akureyri*
      • Best Compromise
      • Best Relay Team*
      • Besta gjöfin
      • Betting
      • Bijele
      • Bilað Lyklaborð
      • Bitte ein Bit
      • Blandað Best
      • Blaðra
      • Blaðra2
      • Bluetooth*
      • Booking a Room
      • Bottle Opening
      • Bounding Robots
      • Breaking Branches*
      • Bracket Matching*
      • Broken Swords
      • Building Pyramids
      • Bus
      • Bus Assignment
      • CPR Number
      • Call for Problems
      • Canadians, eh?
      • Candy Store
      • Cetiri
      • Cetvrta
      • Champernowne Verification
      • Chanukah Challenge
      • Chardonnay
      • Chocolate Division*
      • Chugging
      • Cinema Crowds 2
      • Class Field Trip
      • ASCII Kassi 2
      • Coffee Cup Combo
      • Cold-puter Science
      • Composed Rhythms
      • Cookies
      • Cooking Water
      • Cornhusker
      • Cosmic Path Optimization
      • Count the Vowels
Powered by GitBook
On this page
  • Question
  • Solution
  • Idea
  • Code
Edit on GitHub
  1. Kattis
  2. Easy

ASCII kassi

PreviousACM Contest ScoringNextAaah!

Last updated 6 months ago

Question

Solution

Idea

This is a problem of pattern recognition and breaking big problems into smaller ones to solve. Based on our observation, the first pattern we've found is that the top and bottom line are the same and the middle lines follow the same pattern. So, we can break our problems in print_top_bottom() and print_mid().

In print_top_bottom(), we may find that the start and end are the same, which is +. While the middle part is - and its number is equal to the input N, which is the length of your square.

In print_mid(), firstly, we find that we need to print exactly N lines, and in each line, the start and the end are |, while the middle are N of (white space).

Code

https://open.kattis.com/problems/asciikassiopen.kattis.com
https://github.com/mendax1234/Coding-Problems/blob/main/kattis/asciikassi/asciikassi.c
#include <stdio.h>

#define CORNER '+'
#define TOP '-'
#define SIDE '|'
#define WHITE_SPACE ' '

void print_top_bottom(long n)
{
  putchar(CORNER);
  for (long i = 0; i < n; i += 1)
  {
    putchar(TOP);
  }
  putchar(CORNER);
  putchar('\n');
}

void print_mid(long n)
{
  for (long i = 0; i < n; i += 1)
  {
    putchar(SIDE);
    for (long j = 0; j < n; j += 1)
    {
      putchar(WHITE_SPACE);
    }
    putchar(SIDE);
    putchar('\n');
  }
}

int main()
{
  long n;
  scanf("%ld", &n);
  print_top_bottom(n);
  print_mid(n);
  print_top_bottom(n);
}