zoukankan      html  css  js  c++  java
  • Center Alignment

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93359#problem/B(456321)

    http://codeforces.com/problemset/problem/5/B

    Center Alignment
    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

    Description

    Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.

    You are to implement the alignment in the shortest possible time. Good luck!

    Input

    The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.

    Output

    Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.

    Sample Input

    Input
    This  is

    Codeforces
    Beta
    Round
    5
    Output
    ************
    * This is *
    * *
    *Codeforces*
    * Beta *
    * Round *
    * 5 *
    ************
    Input
    welcome to the
    Codeforces
    Beta
    Round 5

    and
    good luck
    Output
    ****************
    *welcome to the*
    * Codeforces *
    * Beta *
    * Round 5 *
    * *
    * and *
    * good luck *
    ****************

    文章排版问题,让文字居中显示。如果两边不对称时,一个靠左显示,下一个不对称的靠右显示。


    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <iostream>
    #include <map>
    #include <algorithm>
    using namespace std;
    
    #define N 1100
    
    struct node
    {
        char s[N];
        int len;
    }a[N];
    
    int main()
    {
        int n=0, MaxLen=0, i, j;
        char s1[N];
    
        memset(a, 0, sizeof(a));
    
        while(gets(s1))
        {
            strcpy(a[n].s, s1);
            a[n].len = strlen(s1);
            if(a[n].len>MaxLen)
                MaxLen = a[n].len;
            n++;
        }
    
       /// printf("%d
    ", MaxLen);
        for(int i=0; i<MaxLen+2; i++)
            printf("*");
    
        printf("
    ");
    
        int flag = 1, ans;
        for(i=0; i<n; i++)
        {
            printf("*");
            int len = MaxLen-a[i].len;
    
            if(len%2)
                flag = !flag;
    
            ans = (flag+len)/2;
            for(j=1; j<=ans; j++)
                printf(" ");
            printf("%s", a[i].s);
    
            for(j=1; j<=len-ans; j++)
                printf(" ");
    
            printf("*
    ");
        }
    
    
        for(int i=0; i<MaxLen+2; i++)
            printf("*");
    
        printf("
    ");
    
        return 0;
    }
    View Code
    勿忘初心
  • 相关阅读:
    servlet中getWriter和getOutputStream的区别
    一个页面访问错误的问题
    sendRedirect实现原理分析
    servlet开发细节
    tomcat 目录分析
    servlet杂谈
    SQL 查询中的like子句的另一种实现方法,速度比like快
    让复合控件的子控件获得设计时支持
    bug管理工具——Gemini
    HtmlAgilityPack获取#开头节点的XPath
  • 原文地址:https://www.cnblogs.com/YY56/p/4851930.html
Copyright © 2011-2022 走看看