2015 Blue Bridge Cup: 4. In-Grid output

Source: Internet
Author: User

<title>2015 Blue Bridge Cup: 4. In-Grid output</title> 2015 Blue Bridge Cup: 4. In-Grid output
11 points do not know how to use%*s, I thought I C language very good, kneeling ...

The Stringingrid function prints the specified string in a grid of a specified size.
Requires the string to be centered in a horizontal, vertical, two direction.
If the string is too long, it is truncated.
If you can't just center it, you can do it slightly to the left or to a point.

The following program implements this logic, please fill in the missing code in the underlined section.

#include <stdio.h>#include <string.h>void Stringingrid(int width,int Height,Const Char*s){int I,k;Char buf[1000]; strcpy (buf, s);if(strlen (s) >width-2) buf[width-2]=0; printf"+"); for(i=0;i<width-2;i++) printf ("-"); printf"+\n"); for(k=1; k< (height-1)/2;k++) {printf ("|"); for(i=0;i<width-2;i++) printf (" "); printf"|\n"); } printf ("|");//    printf ("%*s%s%*s", _____________________________________________);//fill in the blanksprintf"%*s%s%*s", 5,"", S, 5,"");//Fill inprintf"|\n"); for(k= (height-1)/2+1; k"|"); for(i=0;i<width-2;i++) printf (" "); printf"|\n"); } printf ("+"); for(i=0;i<width-2;i++) printf ("-"); printf"+\n");}int Main() {Stringingrid (20,6,"abcd1234");return0;}

2015 Blue Bridge Cup: 4. In-Grid output

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.