<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