Codeforces Beta Round #5 B. Center Alignment

Source: Internet
Author: User

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

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.