It's a simulation again, just be practiced hand.
Main topic:
Give a paragraph of text, and the output is centered. When the number of left and right blanks is not average, the last left and the next is on.
Problem-solving ideas: See Code ~ ~
Here's the code:
#include <set> #include <map> #include <queue> #include <math.h> #include <vector># Include <string> #include <stdio.h> #include <string.h> #include <stdlib.h> #include < iostream> #include <cctype> #include <algorithm> #define EPS 1e-10#define pi acos ( -1.0) #define INF 107374182#define INF64 1152921504606846976#define LC l,m,tr<<1#define RC m + 1,r,tr<<1|1#define Zero (a) fabs (a) <eps#define iabs (x) ((x) > 0? (x):-(x)) #define CLEAR1 (A, X, SIZE) memset (A, X, sizeof (a[0]) * (min (size,sizeof (a))) #define ClearAll (A, X) memset (A, X , sizeof (a)) #define MEMCOPY1 (A, X, SIZE) memcpy (A, X, sizeof (X[0)) * (size)) #define Memcopyall (A, X) memcpy (A, X, sizeof ( x) #define MAX (x, Y) (((x) > (y))? (x): (y)) #define min (x, y) (((x) < (y))? (x): (y)) using namespace Std;struct node{char s[1005]; int Len;} Line[1005];int Main () {int cnt=0,max1=0; while (gets (LINE[CNT].S)) {Line[cnt].len=sTrlen (LINE[CNT].S); Max1=max (Max1,line[cnt].len); cnt++; } bool Flat=false; for (int i=0;i<max1+2;i++) {printf ("*"); } puts (""); for (int i=0;i<cnt;i++) {printf ("*"); Int J; For (j=0;j< (Max1-line[i].len)/2;j++) {printf (""); } if ((Max1-line[i].len)%2) {if (flat) {printf (""); j + +; Flat=false; } else flat=true; } printf ("%s", LINE[I].S); for (; j<max1-line[i].len;j++) {printf (""); } printf ("*\n"); } for (int i=0;i<max1+2;i++) {printf ("*"); } puts (""); return 0;}
Codeforces Beta Round #5 B. Center Alignment